From cf7f1977ebef54af06ad917c160387dc2015b329 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20Bj=C3=A4reholt?= Date: Wed, 15 Nov 2023 13:03:49 +0100 Subject: [PATCH] feat: added support for query caching in aw-client, fixed so we don't fetch bucket events if vis_timeline is not in the Activity view --- package-lock.json | 26 ++++----- package.json | 2 +- src/components/SelectableVisualization.vue | 1 + src/stores/activity.ts | 65 ++++++++++++++-------- 4 files changed, 56 insertions(+), 38 deletions(-) diff --git a/package-lock.json b/package-lock.json index 8af0cf10..91659d65 100644 --- a/package-lock.json +++ b/package-lock.json @@ -23,7 +23,7 @@ "@types/node": "^12.20.37", "ajv": "^8.12.0", "ajv-keywords": "^5.1.0", - "aw-client": "^0.3.2", + "aw-client": "^0.3.7", "bootstrap": "^4.6.1", "bootstrap-vue": "^2.15.0", "chart.js": "^3.8.0", @@ -8038,17 +8038,17 @@ } }, "node_modules/aw-client": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/aw-client/-/aw-client-0.3.6.tgz", - "integrity": "sha512-nFosUt2DP5n1WNyyVpCgAaa36AmtgLC9c2Dsb1vMUVcbn0TfGvWLbgXnQzzJriylPoEyp3LrGOhVQTBBXBNSFA==", + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/aw-client/-/aw-client-0.3.7.tgz", + "integrity": "sha512-cY7NB06FSUFR1pvz1dnKbqasK5vf96VxjQBhEXG3//52hn87Hk3vfw79rYh2/izYe9eopgMGhn8JTUhvWT7Lkw==", "dependencies": { "axios": "*" } }, "node_modules/axios": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz", - "integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "dependencies": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", @@ -32300,17 +32300,17 @@ "dev": true }, "aw-client": { - "version": "0.3.6", - "resolved": "https://registry.npmjs.org/aw-client/-/aw-client-0.3.6.tgz", - "integrity": "sha512-nFosUt2DP5n1WNyyVpCgAaa36AmtgLC9c2Dsb1vMUVcbn0TfGvWLbgXnQzzJriylPoEyp3LrGOhVQTBBXBNSFA==", + "version": "0.3.7", + "resolved": "https://registry.npmjs.org/aw-client/-/aw-client-0.3.7.tgz", + "integrity": "sha512-cY7NB06FSUFR1pvz1dnKbqasK5vf96VxjQBhEXG3//52hn87Hk3vfw79rYh2/izYe9eopgMGhn8JTUhvWT7Lkw==", "requires": { "axios": "*" } }, "axios": { - "version": "1.5.1", - "resolved": "https://registry.npmjs.org/axios/-/axios-1.5.1.tgz", - "integrity": "sha512-Q28iYCWzNHjAm+yEAot5QaAMxhMghWLFVf7rRdwhUI+c2jix2DUXjAHXVi+s1ibs3mjPO/cCgbA++3BjD0vP/A==", + "version": "1.6.2", + "resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz", + "integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==", "requires": { "follow-redirects": "^1.15.0", "form-data": "^4.0.0", diff --git a/package.json b/package.json index eba57675..1051d4e3 100644 --- a/package.json +++ b/package.json @@ -29,7 +29,7 @@ "@types/node": "^12.20.37", "ajv": "^8.12.0", "ajv-keywords": "^5.1.0", - "aw-client": "^0.3.2", + "aw-client": "^0.3.7", "bootstrap": "^4.6.1", "bootstrap-vue": "^2.15.0", "chart.js": "^3.8.0", diff --git a/src/components/SelectableVisualization.vue b/src/components/SelectableVisualization.vue index 309dfa21..14054e66 100644 --- a/src/components/SelectableVisualization.vue +++ b/src/components/SelectableVisualization.vue @@ -306,6 +306,7 @@ export default { }, methods: { getTimelineBuckets: async function () { + if (this.type != 'vis_timeline') return; if (!this.timeline_daterange) return; await useBucketsStore().ensureLoaded(); diff --git a/src/stores/activity.ts b/src/stores/activity.ts index e4f0031f..e6b91505 100644 --- a/src/stores/activity.ts +++ b/src/stores/activity.ts @@ -339,7 +339,7 @@ export const useActivityStore = defineStore('activity', { host_params: {}, always_active_pattern, }); - const data = await getClient().query(periods, q); + const data = await getClient().query(periods, q, { name: 'multidevice', verbose: true }); const data_window = data[0].window; // Set $color and $score for categories @@ -374,7 +374,10 @@ export const useActivityStore = defineStore('activity', { include_audible, always_active_pattern, }); - const data = await getClient().query(periods, q); + const data = await getClient().query(periods, q, { + name: 'fullDesktopQuery', + verbose: true, + }); const data_window = data[0].window; const data_browser = data[0].browser; @@ -389,15 +392,21 @@ export const useActivityStore = defineStore('activity', { async query_editor({ timeperiod }) { const periods = [timeperiodToStr(timeperiod)]; const q = queries.editorActivityQuery(this.buckets.editor); - const data = await getClient().query(periods, q); + const data = await getClient().query(periods, q, { + name: 'editorActivityQuery', + verbose: true, + }); this.query_editor_completed(data[0]); }, async query_active_history({ timeperiod, ...query_options }: QueryOptions) { const settingsStore = useSettingsStore(); const bucketsStore = useBucketsStore(); + // Filter out periods that are already in the history, and that are in the future const periods = timeperiodStrsAroundTimeperiod(timeperiod).filter(tp_str => { - return !_.includes(this.active.history, tp_str); + return ( + !_.includes(this.active.history, tp_str) && new Date(tp_str.split('/')[0]) < new Date() + ); }); let afk_buckets: string[] = []; if (settingsStore.useMultidevice) { @@ -416,7 +425,11 @@ export const useActivityStore = defineStore('activity', { } else { afk_buckets = [this.buckets.afk[0]]; } - const data = await getClient().query(periods, queries.activityQuery(afk_buckets)); + const query = queries.activityQuery(afk_buckets); + const data = await getClient().query(periods, query, { + name: 'activityQuery', + verbose: true, + }); const active_history = _.zipObject( periods, _.map(data, pair => _.filter(pair, e => e.data.status == 'not-afk')) @@ -453,6 +466,9 @@ export const useActivityStore = defineStore('activity', { console.error(`Unknown timeperiod length: ${timeperiod.length}`); } + // Filter out periods that start in the future + periods = periods.filter(period => new Date(period.split('/')[0]) < new Date()); + const signal = getClient().controller.signal; let cancelled = false; signal.onabort = () => { @@ -487,25 +503,26 @@ export const useActivityStore = defineStore('activity', { } const categories = useCategoryStore().classes_for_query; - const result = await getClient().query( - [period], - // TODO: Clean up call, pass QueryParams in fullDesktopQuery as well - // TODO: Unify QueryOptions and QueryParams - queries.categoryQuery({ - bid_afk: this.buckets.afk[0], - bid_window: this.buckets.window[0], - bid_browsers: this.buckets.browser, - bid_stopwatch: - include_stopwatch && this.buckets.stopwatch.length > 0 - ? this.buckets.stopwatch[0] - : undefined, - // bid_android: this.buckets.android, - categories, - filter_categories, - filter_afk, - always_active_pattern, - }) - ); + // TODO: Clean up call, pass QueryParams in fullDesktopQuery as well + // TODO: Unify QueryOptions and QueryParams + const query = queries.categoryQuery({ + bid_afk: this.buckets.afk[0], + bid_window: this.buckets.window[0], + bid_browsers: this.buckets.browser, + bid_stopwatch: + include_stopwatch && this.buckets.stopwatch.length > 0 + ? this.buckets.stopwatch[0] + : undefined, + // bid_android: this.buckets.android, + categories, + filter_categories, + filter_afk, + always_active_pattern, + }); + const result = await getClient().query([period], query, { + verbose: true, + name: 'categoryQuery', + }); data = data.concat(result); }