Fix commenter-targeted outreach attribution
This commit is contained in:
1 parent
b5304e24e3
commit
f77157d303
19 files changed
+328
-49
No files matched your search
@@ -263,6 +263,31 @@ export class CandidateQueueRepository {
|
||||
`).run(now, now + sendingDelayMs, now).changes;
|
||||
}
|
||||
|
||||
/** Re-prepares legacy commenter drafts without disturbing sends or operator edits. */
|
||||
requeueLegacyCommentPreparations(now: number = Date.now()): number {
|
||||
const rows = this.db.prepare(`
|
||||
SELECT post_id, payload_json, prepared_json FROM candidate_queue
|
||||
WHERE status IN ('ready', 'retryable') AND prepared_json IS NOT NULL
|
||||
`).all() as Array<{ post_id: string; payload_json: string; prepared_json: string }>;
|
||||
const update = this.db.prepare(`
|
||||
UPDATE candidate_queue
|
||||
SET status = 'discovered', prepared_json = NULL, available_at = ?, updated_at = ?,
|
||||
lease_owner = NULL, lease_expires_at = NULL, assigned_account_id = NULL,
|
||||
last_error = 'Requeued for commenter opener contract upgrade'
|
||||
WHERE post_id = ? AND status IN ('ready', 'retryable')
|
||||
`);
|
||||
return this.db.transaction(() => {
|
||||
let requeued = 0;
|
||||
for (const row of rows) {
|
||||
const post = JSON.parse(row.payload_json) as RedditPost;
|
||||
const prepared = JSON.parse(row.prepared_json) as ProcessedPost;
|
||||
if (!post.targetComment || prepared.operatorEdited || prepared.openerContract === 'comment-author-v2') continue;
|
||||
requeued += update.run(now, now, row.post_id).changes;
|
||||
}
|
||||
return requeued;
|
||||
})();
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancels every candidate that cannot already be crossing the remote-send
|
||||
* boundary. Sending leases are deliberately retained because their Matrix
|
||||
|
||||
Reference in new issue
Block a user