Skip to content

chore: disable auto proxy selection based on latency #8137

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Remove latency pulled from storage
  • Loading branch information
Emyrk committed Jun 21, 2023
commit efb3bf60ee73c0fe2561409623288ea916f4e0fc
30 changes: 3 additions & 27 deletions site/src/contexts/useProxyLatency.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,8 @@ const proxyLatenciesReducer = (
state: Record<string, ProxyLatencyReport>,
action: ProxyLatencyAction,
): Record<string, ProxyLatencyReport> => {
// TODO: We should probably not read from local storage on every action.
const history = loadStoredLatencies()
const proxyHistory = history[action.proxyID] || []
const minReport = proxyHistory.reduce((min, report) => {
if (min.latencyMS === 0) {
// Not yet set, so use the new report.
return report
}
if (min.latencyMS < report.latencyMS) {
return min
}
return report
}, {} as ProxyLatencyReport)

if (
minReport.latencyMS > 0 &&
minReport.latencyMS < action.report.latencyMS
) {
// The new report is slower then the min report, so use the min report.
return {
...state,
[action.proxyID]: minReport,
}
}

// Use the new report
// Always return the new report. We have some saved latencies, but until we have a better
// way to utilize them, we will ignore them for all practical purposes.
return {
...state,
[action.proxyID]: action.report,
Expand All @@ -65,7 +41,7 @@ export const useProxyLatency = (
proxyLatencies: Record<string, ProxyLatencyReport>
} => {
// maxStoredLatencies is the maximum number of latencies to store per proxy in local storage.
let maxStoredLatencies = 8
let maxStoredLatencies = 1
// The reason we pull this from local storage is so for development purposes, a user can manually
// set a larger number to collect data in their normal usage. This data can later be analyzed to come up
// with some better magic numbers.
Expand Down