Refactor clipboard cleanup logic to use configurable days parameter

- Introduced a variable `nDays` to allow dynamic adjustment of the clipboard cleanup threshold.
- Updated logging to reflect the configurable number of days for clipboard entry deletion instead of a hardcoded value.
This commit is contained in:
Huakun Shen 2025-04-03 10:57:48 -04:00
parent e9e814b23f
commit 211b131efd
No known key found for this signature in database

View File

@ -7,9 +7,10 @@ import * as orm from "drizzle-orm"
* For now, simply delete all clipboard data older than 10 days * For now, simply delete all clipboard data older than 10 days
*/ */
export async function cleanClipboard() { export async function cleanClipboard() {
const nDays = 10
const clipboardExt = await getExtClipboard() const clipboardExt = await getExtClipboard()
const tenDaysAgo = new Date() const nDaysAgo = new Date()
tenDaysAgo.setDate(tenDaysAgo.getDate() - 8) nDaysAgo.setDate(nDaysAgo.getDate() - nDays)
try { try {
// Select data older than 10 days to check what will be deleted // Select data older than 10 days to check what will be deleted
@ -19,11 +20,11 @@ export async function cleanClipboard() {
.where( .where(
orm.and( orm.and(
orm.eq(schema.extensionData.extId, clipboardExt.extId), orm.eq(schema.extensionData.extId, clipboardExt.extId),
orm.lt(schema.extensionData.createdAt, tenDaysAgo.toISOString()) orm.lt(schema.extensionData.createdAt, nDaysAgo.toISOString())
) )
) )
const nLinesToDelete = oldClipboardData.at(0)?.count ?? 0 const nLinesToDelete = oldClipboardData.at(0)?.count ?? 0
info(`Found ${nLinesToDelete} clipboard entries older than 10 days to clean up`) info(`Found ${nLinesToDelete} clipboard entries older than ${nDays} days to clean up`)
// Now delete the old data // Now delete the old data
const deleted = await proxyDB const deleted = await proxyDB
@ -31,7 +32,7 @@ export async function cleanClipboard() {
.where( .where(
orm.and( orm.and(
orm.eq(schema.extensionData.extId, clipboardExt.extId), orm.eq(schema.extensionData.extId, clipboardExt.extId),
orm.lt(schema.extensionData.createdAt, tenDaysAgo.toISOString()) orm.lt(schema.extensionData.createdAt, nDaysAgo.toISOString())
) )
) )