@@ -3,6 +3,7 @@ import { open } from '@tauri-apps/plugin-dialog';
33
44import { AnalyticsLibrary } from '@/components/analytics/AnalyticsLibrary' ;
55import { TransferSelectionPanel } from '@/components/analytics/TransferSelectionPanel' ;
6+ import { advancedAnalyticsRequestCacheKey } from '@/lib/analytics/cacheKey' ;
67import {
78 buildAdvancedAnalyticsTransferFile ,
89 mergeAdvancedAnalyticsTransferData ,
@@ -79,34 +80,6 @@ function AnalyticsLoadingBar({
7980 ) ;
8081}
8182
82- function requestCacheKey ( request : AdvancedAnalyticsRunRequest , dataVersion : string | null ) {
83- const requestSignature = {
84- startDate : request . startDate ,
85- endDate : request . endDate ,
86- metrics : request . metrics . map ( ( metric ) => ( {
87- id : metric . id ,
88- kind : metric . kind ,
89- base : metric . base ,
90- formula : metric . formula
91- } ) ) ,
92- streaks : request . streaks . map ( ( streak ) => ( {
93- id : streak . id ,
94- metricId : streak . metricId ,
95- additionalMetricIds : streak . additionalMetricIds ,
96- period : streak . period ,
97- thresholdOperator : streak . thresholdOperator ,
98- thresholdValue : streak . thresholdValue
99- } ) ) ,
100- charts : request . charts . map ( ( chart ) => ( {
101- id : chart . id ,
102- chartType : chart . chartType ,
103- metricIds : chart . metricIds ,
104- granularity : chart . granularity
105- } ) )
106- } ;
107- return JSON . stringify ( { request : requestSignature , dataVersion } ) ;
108- }
109-
11083function buildRequest (
11184 range : { startDate ?: string ; endDate ?: string } ,
11285 metrics : AdvancedAnalyticsRunRequest [ 'metrics' ] ,
@@ -217,7 +190,7 @@ export function AdvancedAnalyticsPage() {
217190 const request = buildRequest ( range , metrics , streaks , charts ) ;
218191 return {
219192 request,
220- cacheKey : requestCacheKey ( request , dataVersion )
193+ cacheKey : advancedAnalyticsRequestCacheKey ( request , dataVersion )
221194 } ;
222195 } , [ charts , dataVersion , metrics , selectedItem , streaks ] ) ;
223196
@@ -238,7 +211,7 @@ export function AdvancedAnalyticsPage() {
238211 const request = buildRequest ( range , metrics , streaks , charts ) ;
239212 byRangeKey . set ( key , {
240213 request,
241- cacheKey : requestCacheKey ( request , dataVersion )
214+ cacheKey : advancedAnalyticsRequestCacheKey ( request , dataVersion )
242215 } ) ;
243216 }
244217
@@ -367,7 +340,7 @@ export function AdvancedAnalyticsPage() {
367340 for ( const metric of viewTabMetrics ) {
368341 const range = resolveAdvancedAnalyticsTimeRange ( metric . timeRange ) ;
369342 const request = buildRequest ( range , metrics , streaks , charts ) ;
370- const cacheKey = requestCacheKey ( request , dataVersion ) ;
343+ const cacheKey = advancedAnalyticsRequestCacheKey ( request , dataVersion ) ;
371344 const response = getResponse ( cacheKey ) ;
372345 results [ metric . id ] = response ?. metricResults [ metric . id ] ;
373346 }
@@ -379,7 +352,7 @@ export function AdvancedAnalyticsPage() {
379352 for ( const streak of streaks ) {
380353 const range = resolveAdvancedAnalyticsTimeRange ( STREAK_FIXED_TIME_RANGE ) ;
381354 const request = buildRequest ( range , metrics , streaks , charts ) ;
382- const cacheKey = requestCacheKey ( request , dataVersion ) ;
355+ const cacheKey = advancedAnalyticsRequestCacheKey ( request , dataVersion ) ;
383356 const response = getResponse ( cacheKey ) ;
384357 results [ streak . id ] = response ?. streakResults [ streak . id ] ;
385358 }
@@ -391,7 +364,7 @@ export function AdvancedAnalyticsPage() {
391364 for ( const chart of charts ) {
392365 const range = resolveAdvancedAnalyticsTimeRange ( chart . timeRange ) ;
393366 const request = buildRequest ( range , metrics , streaks , charts ) ;
394- const cacheKey = requestCacheKey ( request , dataVersion ) ;
367+ const cacheKey = advancedAnalyticsRequestCacheKey ( request , dataVersion ) ;
395368 const response = getResponse ( cacheKey ) ;
396369 results [ chart . id ] = response ?. chartResults [ chart . id ] ;
397370 }
0 commit comments