Skip to content

Commit

Permalink
feat: added support for query caching in aw-client, fixed so we don't…
Browse files Browse the repository at this point in the history
… fetch bucket events if vis_timeline is not in the Activity view
  • Loading branch information
ErikBjare committed Nov 15, 2023
1 parent a3f9e7d commit cf7f197
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 38 deletions.
26 changes: 13 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions src/components/SelectableVisualization.vue
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@ export default {
},
methods: {
getTimelineBuckets: async function () {
if (this.type != 'vis_timeline') return;
if (!this.timeline_daterange) return;
await useBucketsStore().ensureLoaded();
Expand Down
65 changes: 41 additions & 24 deletions src/stores/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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) {
Expand All @@ -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'))
Expand Down Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -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);
}

Expand Down

1 comment on commit cf7f197

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here are screenshots of this commit:

Screenshots using aw-server v0.12.3b11 (click to expand)

Screenshots using aw-server-rust master (click to expand)

Screenshots using aw-server-rust v0.12.3b11 (click to expand)

Please sign in to comment.