Prioritize growth retries and randomize intake

This commit is contained in:
jjbrunton committed 2026-08-11 21:14:30 +01:00
1 parent b949b6ee37
commit e2d7dc4b82
11 files changed
+142 -4

No files matched your search

+29 -1
View File
@@ -460,7 +460,11 @@ export class AccountGrowthRepository {
const row = this.db.prepare(`
SELECT post_id FROM account_growth_comments
WHERE account_id = ? AND status IN ('discovered', 'retryable') AND available_at <= ?
ORDER BY thread_created_at DESC, discovered_at ASC
ORDER BY
CASE status WHEN 'retryable' THEN 0 ELSE 1 END,
CASE status WHEN 'retryable' THEN available_at END ASC,
thread_created_at DESC,
discovered_at ASC
LIMIT 1
`).get(accountId, now) as { post_id: string } | undefined;
if (!row) return null;
@@ -474,6 +478,30 @@ export class AccountGrowthRepository {
})();
}
/**
* Includes retries whose cooldown is still active. Discovery uses this to
* avoid growing the backlog while existing work is waiting to recover.
*/
hasPendingQueueWork(accountId: string): boolean {
return this.db.prepare(`
SELECT 1 FROM account_growth_comments
WHERE account_id = ? AND status IN ('discovered', 'retryable')
LIMIT 1
`).get(accountId) !== undefined;
}
/**
* Clears only work that has not reached Reddit. A posting lease is excluded
* because its remote outcome may be uncertain, and posted audit history is
* never touched.
*/
clearPendingQueue(accountId: string): number {
return this.db.prepare(`
DELETE FROM account_growth_comments
WHERE account_id = ? AND status IN ('discovered', 'retryable')
`).run(accountId).changes;
}
markPosted(
accountId: string,
postId: string,