Skip to content

Commit 33784bd

Browse files
authored
feat: added support for query caching in aw-client (#501)
1 parent a3f9e7d commit 33784bd

File tree

4 files changed

+56
-38
lines changed

4 files changed

+56
-38
lines changed

package-lock.json

Lines changed: 13 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
"@types/node": "^12.20.37",
3030
"ajv": "^8.12.0",
3131
"ajv-keywords": "^5.1.0",
32-
"aw-client": "^0.3.2",
32+
"aw-client": "^0.3.7",
3333
"bootstrap": "^4.6.1",
3434
"bootstrap-vue": "^2.15.0",
3535
"chart.js": "^3.8.0",

src/components/SelectableVisualization.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,7 @@ export default {
306306
},
307307
methods: {
308308
getTimelineBuckets: async function () {
309+
if (this.type != 'vis_timeline') return;
309310
if (!this.timeline_daterange) return;
310311
311312
await useBucketsStore().ensureLoaded();

src/stores/activity.ts

Lines changed: 41 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,7 @@ export const useActivityStore = defineStore('activity', {
339339
host_params: {},
340340
always_active_pattern,
341341
});
342-
const data = await getClient().query(periods, q);
342+
const data = await getClient().query(periods, q, { name: 'multidevice', verbose: true });
343343
const data_window = data[0].window;
344344

345345
// Set $color and $score for categories
@@ -374,7 +374,10 @@ export const useActivityStore = defineStore('activity', {
374374
include_audible,
375375
always_active_pattern,
376376
});
377-
const data = await getClient().query(periods, q);
377+
const data = await getClient().query(periods, q, {
378+
name: 'fullDesktopQuery',
379+
verbose: true,
380+
});
378381
const data_window = data[0].window;
379382
const data_browser = data[0].browser;
380383

@@ -389,15 +392,21 @@ export const useActivityStore = defineStore('activity', {
389392
async query_editor({ timeperiod }) {
390393
const periods = [timeperiodToStr(timeperiod)];
391394
const q = queries.editorActivityQuery(this.buckets.editor);
392-
const data = await getClient().query(periods, q);
395+
const data = await getClient().query(periods, q, {
396+
name: 'editorActivityQuery',
397+
verbose: true,
398+
});
393399
this.query_editor_completed(data[0]);
394400
},
395401

396402
async query_active_history({ timeperiod, ...query_options }: QueryOptions) {
397403
const settingsStore = useSettingsStore();
398404
const bucketsStore = useBucketsStore();
405+
// Filter out periods that are already in the history, and that are in the future
399406
const periods = timeperiodStrsAroundTimeperiod(timeperiod).filter(tp_str => {
400-
return !_.includes(this.active.history, tp_str);
407+
return (
408+
!_.includes(this.active.history, tp_str) && new Date(tp_str.split('/')[0]) < new Date()
409+
);
401410
});
402411
let afk_buckets: string[] = [];
403412
if (settingsStore.useMultidevice) {
@@ -416,7 +425,11 @@ export const useActivityStore = defineStore('activity', {
416425
} else {
417426
afk_buckets = [this.buckets.afk[0]];
418427
}
419-
const data = await getClient().query(periods, queries.activityQuery(afk_buckets));
428+
const query = queries.activityQuery(afk_buckets);
429+
const data = await getClient().query(periods, query, {
430+
name: 'activityQuery',
431+
verbose: true,
432+
});
420433
const active_history = _.zipObject(
421434
periods,
422435
_.map(data, pair => _.filter(pair, e => e.data.status == 'not-afk'))
@@ -453,6 +466,9 @@ export const useActivityStore = defineStore('activity', {
453466
console.error(`Unknown timeperiod length: ${timeperiod.length}`);
454467
}
455468

469+
// Filter out periods that start in the future
470+
periods = periods.filter(period => new Date(period.split('/')[0]) < new Date());
471+
456472
const signal = getClient().controller.signal;
457473
let cancelled = false;
458474
signal.onabort = () => {
@@ -487,25 +503,26 @@ export const useActivityStore = defineStore('activity', {
487503
}
488504

489505
const categories = useCategoryStore().classes_for_query;
490-
const result = await getClient().query(
491-
[period],
492-
// TODO: Clean up call, pass QueryParams in fullDesktopQuery as well
493-
// TODO: Unify QueryOptions and QueryParams
494-
queries.categoryQuery({
495-
bid_afk: this.buckets.afk[0],
496-
bid_window: this.buckets.window[0],
497-
bid_browsers: this.buckets.browser,
498-
bid_stopwatch:
499-
include_stopwatch && this.buckets.stopwatch.length > 0
500-
? this.buckets.stopwatch[0]
501-
: undefined,
502-
// bid_android: this.buckets.android,
503-
categories,
504-
filter_categories,
505-
filter_afk,
506-
always_active_pattern,
507-
})
508-
);
506+
// TODO: Clean up call, pass QueryParams in fullDesktopQuery as well
507+
// TODO: Unify QueryOptions and QueryParams
508+
const query = queries.categoryQuery({
509+
bid_afk: this.buckets.afk[0],
510+
bid_window: this.buckets.window[0],
511+
bid_browsers: this.buckets.browser,
512+
bid_stopwatch:
513+
include_stopwatch && this.buckets.stopwatch.length > 0
514+
? this.buckets.stopwatch[0]
515+
: undefined,
516+
// bid_android: this.buckets.android,
517+
categories,
518+
filter_categories,
519+
filter_afk,
520+
always_active_pattern,
521+
});
522+
const result = await getClient().query([period], query, {
523+
verbose: true,
524+
name: 'categoryQuery',
525+
});
509526
data = data.concat(result);
510527
}
511528

0 commit comments

Comments
 (0)