mirror of
https://github.com/Litlyx/litlyx
synced 2025-12-10 07:48:37 +01:00
implementing snapshots
This commit is contained in:
@@ -87,12 +87,18 @@ export function usePagesData(website: string, limit: number = 10) {
|
||||
|
||||
}
|
||||
|
||||
const { safeSnapshotDates } = useSnapshot()
|
||||
|
||||
export function useWebsitesData(limit: number = 10) {
|
||||
const activeProject = useActiveProject();
|
||||
const res = useFetch<VisitsWebsiteAggregated[]>(`/api/metrics/${activeProject.value?._id}/data/websites`, {
|
||||
...signHeaders({ 'x-query-limit': limit.toString() }),
|
||||
key: `websites_data:${limit}`,
|
||||
lazy: true
|
||||
...signHeaders({
|
||||
'x-query-limit': limit.toString(),
|
||||
'x-from': safeSnapshotDates.value.from,
|
||||
'x-to': safeSnapshotDates.value.to
|
||||
}),
|
||||
key: `websites_data:${limit}:${safeSnapshotDates.value.from}:${safeSnapshotDates.value.to}`,
|
||||
lazy: true,
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
26
dashboard/composables/useSnapshot.ts
Normal file
26
dashboard/composables/useSnapshot.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
import type { TProjectSnapshot } from "@schema/ProjectSnapshot";
|
||||
|
||||
const snapshots = useFetch<TProjectSnapshot[]>('/api/project/snapshots', {
|
||||
...signHeaders(),
|
||||
immediate: false
|
||||
});
|
||||
|
||||
const snapshot = ref<TProjectSnapshot>();
|
||||
|
||||
watch(snapshots.data, () => {
|
||||
if (!snapshots.data.value) return;
|
||||
snapshot.value = snapshots.data.value[0];
|
||||
});
|
||||
|
||||
const safeSnapshotDates = computed(() => {
|
||||
const from = new Date(snapshot.value?.from || 0).toISOString();
|
||||
const to = new Date(snapshot.value?.to || Date.now()).toISOString();
|
||||
return { from, to }
|
||||
})
|
||||
|
||||
export function useSnapshot() {
|
||||
if (snapshots.status.value === 'idle') {
|
||||
snapshots.execute();
|
||||
}
|
||||
return { snapshot, snapshots, safeSnapshotDates }
|
||||
}
|
||||
Reference in New Issue
Block a user