-
-
Notifications
You must be signed in to change notification settings - Fork 347
优化公开状态页 Redis 聚合与轮询性能 #1211
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
优化公开状态页 Redis 聚合与轮询性能 #1211
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -49,6 +49,10 @@ import { SortableGroupPanel } from "./sortable-group-panel"; | |
| import { StatusHero } from "./status-hero"; | ||
| import { StatusToolbar } from "./status-toolbar"; | ||
|
|
||
| type ViewModelSnapshot = PublicStatusPayload["groups"][number]["models"][number] & { | ||
| timelineReusedFromPrevious?: boolean; | ||
| }; | ||
|
|
||
| interface PublicStatusViewProps { | ||
| initialPayload: PublicStatusPayload; | ||
| initialStatus?: PublicStatusRouteStatus; | ||
|
|
@@ -151,6 +155,17 @@ function aggregateByFailed(states: DisplayState[]): DisplayState { | |
| return "operational"; | ||
| } | ||
|
|
||
| function deriveCurrentModelState(model: ViewModelSnapshot): DisplayState { | ||
| if (model.timeline.length === 0 || model.timelineReusedFromPrevious) { | ||
| return model.latestState; | ||
| } | ||
| return deriveLatestModelState(model); | ||
| } | ||
|
|
||
| function shouldUseServerModelSummary(model: ViewModelSnapshot): boolean { | ||
| return model.timeline.length === 0 || Boolean(model.timelineReusedFromPrevious); | ||
| } | ||
|
|
||
| export function PublicStatusView({ | ||
| initialPayload, | ||
| initialStatus, | ||
|
|
@@ -184,6 +199,7 @@ export function PublicStatusView({ | |
| if (filterSlug) { | ||
| params.set("groupSlug", filterSlug); | ||
| } | ||
| params.set("include", "meta,defaults,groups"); | ||
| const requestUrl = | ||
| params.size > 0 ? `/api/public-status?${params.toString()}` : "/api/public-status"; | ||
| const response = await fetch(requestUrl, { cache: "no-store" }); | ||
|
|
@@ -195,7 +211,35 @@ export function PublicStatusView({ | |
| ? { ...next, groups: next.groups.filter((g) => g.publicGroupSlug === filterSlug) } | ||
| : next; | ||
| startTransition(() => { | ||
| setPayload(scoped); | ||
| setPayload((previous) => ({ | ||
| ...scoped, | ||
| groups: scoped.groups.map((group) => { | ||
| const previousGroup = previous.groups.find( | ||
| (candidate) => candidate.publicGroupSlug === group.publicGroupSlug | ||
| ); | ||
| if (!previousGroup) { | ||
| return group; | ||
| } | ||
|
Comment on lines
+220
to
+222
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Polling always requests Useful? React with 👍 / 👎. |
||
|
|
||
| return { | ||
| ...group, | ||
| models: group.models.map((model) => { | ||
| const previousModel = previousGroup.models.find( | ||
| (candidate) => candidate.publicModelKey === model.publicModelKey | ||
| ); | ||
| if (model.timeline.length > 0) { | ||
| return model; | ||
| } | ||
|
|
||
| return { | ||
| ...model, | ||
| timeline: previousModel?.timeline ?? [], | ||
| timelineReusedFromPrevious: Boolean(previousModel?.timeline.length), | ||
| }; | ||
| }), | ||
| }; | ||
| }), | ||
| })); | ||
| setRouteStatus(nextResponse.status); | ||
| }); | ||
| } catch { | ||
|
|
@@ -222,9 +266,14 @@ export function PublicStatusView({ | |
| const derivedModels = group.models.map((model) => { | ||
| const filled = fillDisplayTimeline(model.timeline); | ||
| const chartCells = sliceTimelineForChart(filled, CHART_BUCKETS); | ||
| const uptime24h = computeUptimePct(model.timeline); | ||
| const viewModel = model as ViewModelSnapshot; | ||
| const useServerSummary = shouldUseServerModelSummary(viewModel); | ||
| const uptime24h = | ||
| useServerSummary && model.availabilityPct !== null | ||
| ? model.availabilityPct | ||
| : computeUptimePct(model.timeline); | ||
| const ttfb24h = computeAvgTtfb(model.timeline); | ||
| const latest = deriveLatestModelState(model); | ||
| const latest = deriveCurrentModelState(viewModel); | ||
| return { model, chartCells, uptime24h, ttfb24h, latest }; | ||
| }); | ||
| const issueCount = derivedModels.filter((d) => d.latest === "failed").length; | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.