@@ -90,9 +90,7 @@ import {
9090} from "~/api/materialize/cluster/replicaUtilizationHistory" ;
9191import {
9292 calculateBucketSizeFromLookback ,
93- fetchLatestLag ,
9493 fetchObjectLagHistory ,
95- LATEST_READING_INTERVAL_MS ,
9694} from "~/api/materialize/freshness/lagHistory" ;
9795import { assertNoMoreThanOneRow } from "~/api/materialize/MoreThanOneRowError" ;
9896import { fetchOwners } from "~/api/materialize/owners" ;
@@ -203,15 +201,6 @@ export const clusterQueryKeys = {
203201 objectIds : [ ...params . objectIds ] . sort ( ) . join ( "," ) ,
204202 } ) ,
205203 ] as const ,
206- // No lookback: the newest reading is the newest reading whatever range is
207- // being graphed, so changing the range must not refetch it.
208- clusterFreshnessLatest : ( params : { objectIds : string [ ] } ) =>
209- [
210- ...clusterQueryKeys . all ( ) ,
211- buildQueryKeyPart ( "clusterFreshnessLatest" , {
212- objectIds : [ ...params . objectIds ] . sort ( ) . join ( "," ) ,
213- } ) ,
214- ] as const ,
215204 replicaUtilization : ( ) =>
216205 [
217206 ...clusterQueryKeys . all ( ) ,
@@ -980,25 +969,19 @@ export interface FreshnessObject {
980969type LagReading = Awaited <
981970 ReturnType < typeof fetchObjectLagHistory >
982971> [ "rows" ] [ number ] ;
983- type LatestReading = Awaited < ReturnType < typeof fetchLatestLag > > [ "rows" ] [ number ] ;
984-
985- export interface LagQueryRows {
986- /** One binned point per object per bin, each the worst reading in its span. */
987- readings : LagReading [ ] ;
988- /** One row per object, its most recent reading. */
989- latest : LatestReading [ ] ;
990- }
991-
992972/**
993973 * Shapes lag readings for the freshness graph, naming each object from the
994974 * caller's list.
995975 *
996976 * Separate from the query so names are not cached with the readings: the query
997977 * key tracks which objects were asked for, not what they are called, so a
998978 * rename would otherwise survive in the cache until the set changed.
979+ *
980+ * @param readings One binned point per object per bin, each the worst reading
981+ * in its span.
999982 */
1000983export function buildFreshnessData (
1001- { readings, latest } : LagQueryRows ,
984+ readings : LagReading [ ] ,
1002985 objects : FreshnessObject [ ] ,
1003986) {
1004987 // Everything below reads row order as time order: the graph's start and end,
@@ -1011,15 +994,6 @@ export function buildFreshnessData(
1011994 objects . map ( ( object ) => [ object . objectId , object ] ) ,
1012995 ) ;
1013996
1014- // Null where the newest reading reports the object as unreadable, which is
1015- // not the same as the object having no reading at all.
1016- const latestByObjectId = new Map < string , number | null > (
1017- latest . map ( ( row ) => [
1018- row . objectId ,
1019- row . lag === null ? null : sumPostgresIntervalMs ( row . lag ) ,
1020- ] ) ,
1021- ) ;
1022-
1023997 const currentData = flatGroup ( rows , ( d ) => d . objectId )
1024998 . map ( ( [ , rowsByObjectId ] ) => rowsByObjectId . at ( - 1 ) )
1025999 . filter ( notNullOrUndefined )
@@ -1093,7 +1067,6 @@ export function buildFreshnessData(
10931067 historicalData,
10941068 currentData,
10951069 objectsById,
1096- latestByObjectId,
10971070 lines : Array . from ( lines . values ( ) ) ,
10981071 startTime : historicalData . at ( 0 ) ?. timestamp ?? 0 ,
10991072 endTime : historicalData . at ( - 1 ) ?. timestamp ?? 0 ,
@@ -1143,40 +1116,14 @@ export function useClusterFreshness({
11431116 refetchInterval : binSizeMs ,
11441117 } ) ;
11451118
1146- const latest = useQuery ( {
1147- queryKey : clusterQueryKeys . clusterFreshnessLatest ( { objectIds } ) ,
1148- queryFn : async ( { queryKey, signal } ) : Promise < LatestReading [ ] > => {
1149- if ( objectIds . length === 0 ) return [ ] ;
1150-
1151- const { rows } = await fetchLatestLag ( {
1152- objectIds,
1153- requestOptions : { signal } ,
1154- queryKey,
1155- } ) ;
1156- return rows ;
1157- } ,
1158- // A reading lands once a minute, so anything shorter re-asks a question
1159- // whose answer cannot have changed.
1160- staleTime : LATEST_READING_INTERVAL_MS ,
1161- refetchInterval : LATEST_READING_INTERVAL_MS ,
1162- } ) ;
1163-
1164- // Undefined until both have answered. Building from one alone would show a
1165- // graph whose "Now" column disagrees with it.
11661119 const data = useMemo (
1167- ( ) =>
1168- series . data && latest . data
1169- ? buildFreshnessData (
1170- { readings : series . data , latest : latest . data } ,
1171- objects ,
1172- )
1173- : undefined ,
1174- [ series . data , latest . data , objects ] ,
1120+ ( ) => ( series . data ? buildFreshnessData ( series . data , objects ) : undefined ) ,
1121+ [ series . data , objects ] ,
11751122 ) ;
11761123
11771124 // Only these fields are returned. Spreading a query object would make every
11781125 // consumer observe all of its state.
1179- return { data, isError : series . isError || latest . isError } ;
1126+ return { data, isError : series . isError } ;
11801127}
11811128
11821129export type FreshnessData = ReturnType < typeof buildFreshnessData > ;
0 commit comments