feat: Add /cleanup admin command and enhance lootdrop cleanup service to optionally include claimed items.
This commit is contained in:
@@ -27,7 +27,7 @@ class LootdropService {
|
||||
// Cleanup interval for activity tracking and expired lootdrops
|
||||
setInterval(() => {
|
||||
this.cleanupActivity();
|
||||
this.cleanupExpiredLootdrops();
|
||||
this.cleanupExpiredLootdrops(true);
|
||||
}, 60000);
|
||||
}
|
||||
|
||||
@@ -45,16 +45,24 @@ class LootdropService {
|
||||
}
|
||||
}
|
||||
|
||||
private async cleanupExpiredLootdrops() {
|
||||
public async cleanupExpiredLootdrops(includeClaimed: boolean = false): Promise<number> {
|
||||
try {
|
||||
const now = new Date();
|
||||
await DrizzleClient.delete(lootdrops)
|
||||
.where(and(
|
||||
isNull(lootdrops.claimedBy),
|
||||
lt(lootdrops.expiresAt, now)
|
||||
));
|
||||
const whereClause = includeClaimed
|
||||
? lt(lootdrops.expiresAt, now)
|
||||
: and(isNull(lootdrops.claimedBy), lt(lootdrops.expiresAt, now));
|
||||
|
||||
const result = await DrizzleClient.delete(lootdrops)
|
||||
.where(whereClause)
|
||||
.returning();
|
||||
|
||||
if (result.length > 0) {
|
||||
console.log(`[LootdropService] Cleaned up ${result.length} expired lootdrops.`);
|
||||
}
|
||||
return result.length;
|
||||
} catch (error) {
|
||||
console.error("Failed to cleanup lootdrops:", error);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user