Skip to content

Commit

Permalink
🐛 fix: upsertKvStore
Browse files Browse the repository at this point in the history
  • Loading branch information
yunsii committed Mar 22, 2024
1 parent 922fd72 commit 1d5d254
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/worker/_helpers/store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ export async function upsertKvStore(value: DataV1 | null, allMonitors: Monitor[]

export async function cleanDataV1(value: DataV1, allMonitors: Monitor[]) {
const { bytes } = memorySizeOf(JSON.stringify(value))
// eslint-disable-next-line no-console
console.debug('value bytes', bytes)

// https://developers.cloudflare.com/kv/platform/limits/
// Value max size 25 MiB, in case of exceptions, we clean data when bytes bigger than 24 MiB.
Expand All @@ -98,13 +100,16 @@ export async function cleanDataV1(value: DataV1, allMonitors: Monitor[]) {
return allMonitors.some((monitorItem) => monitorItem.id === item)
}).reduce<Record<string, MonitorAllData>>((previous, current) => {
const { checks, ...restHistoryData } = monitorHistoryData[current]
return { ...previous, current: {
...restHistoryData,
// Remove dates older than config.settings.displayDays
checks: checks.filter((item) => {
return historyDates.includes(item.date)
}),
} }
return {
...previous,
[current]: {
...restHistoryData,
// Remove dates older than config.settings.displayDays
checks: checks.filter((item) => {
return historyDates.includes(item.date)
}),
},
}
}, {})),
}
}
Expand Down

0 comments on commit 1d5d254

Please sign in to comment.