mirror of
https://github.com/dreamhunter2333/cloudflare_temp_email.git
synced 2026-09-05 07:27:27 +08:00
perf: throttle address activity updates (#1104)
* perf: throttle address activity updates * docs: record address activity write throttling * refactor: inline address activity interval * test: cover address activity throttling
This commit is contained in:
+26
-2
@@ -250,10 +250,34 @@ export function updateAddressUpdatedAt(
|
||||
c.executionCtx.waitUntil((async () => {
|
||||
try {
|
||||
await c.env.DB.prepare(
|
||||
`UPDATE address SET updated_at = datetime('now') where name = ?`
|
||||
`UPDATE address SET updated_at = datetime('now')`
|
||||
+ ` WHERE name = ?`
|
||||
+ ` AND (updated_at IS NULL OR updated_at < datetime('now', '-1 day'))`
|
||||
).bind(address).run();
|
||||
} catch (e) {
|
||||
console.warn("[updateAddressUpdatedAt] failed:", address, e);
|
||||
const errorName = e instanceof Error ? e.name : "UnknownError";
|
||||
console.warn("[updateAddressUpdatedAt] failed:", errorName);
|
||||
}
|
||||
})());
|
||||
}
|
||||
|
||||
export function updateUserAddressesUpdatedAt(
|
||||
c: Context<HonoCustomType>,
|
||||
userId: number | string | undefined | null
|
||||
): void {
|
||||
if (!userId) {
|
||||
return;
|
||||
}
|
||||
c.executionCtx.waitUntil((async () => {
|
||||
try {
|
||||
await c.env.DB.prepare(
|
||||
`UPDATE address SET updated_at = datetime('now')`
|
||||
+ ` WHERE id IN (SELECT address_id FROM users_address WHERE user_id = ?)`
|
||||
+ ` AND (updated_at IS NULL OR updated_at < datetime('now', '-1 day'))`
|
||||
).bind(userId).run();
|
||||
} catch (e) {
|
||||
const errorName = e instanceof Error ? e.name : "UnknownError";
|
||||
console.warn("[updateUserAddressesUpdatedAt] failed:", errorName);
|
||||
}
|
||||
})());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user