Harden conversation replies and prioritize newest candidates
This commit is contained in:
1 parent
f98c5c732d
commit
b8e4a1bb88
23 files changed
+598
-113
No files matched your search
@@ -96,10 +96,11 @@ export class CandidateQueueRepository {
|
||||
) VALUES (?, ?, ?, ?, ?, ?, ?, 'discovered', ?, ?, ?)
|
||||
`);
|
||||
|
||||
const newestPostsFirst = [...posts].sort((left, right) => right.created_utc - left.created_utc);
|
||||
this.db.transaction(() => {
|
||||
for (const [index, post] of posts.entries()) {
|
||||
for (const [index, post] of newestPostsFirst.entries()) {
|
||||
if (result.discovered >= maxNewCandidates) {
|
||||
result.deferredAtCapacity += posts.length - index;
|
||||
result.deferredAtCapacity += newestPostsFirst.length - index;
|
||||
break;
|
||||
}
|
||||
if (existingPost.get(post.id)) {
|
||||
@@ -214,7 +215,7 @@ export class CandidateQueueRepository {
|
||||
WHERE post_id IN (
|
||||
SELECT post_id FROM candidate_queue
|
||||
WHERE status = 'retryable' AND available_at <= ?
|
||||
ORDER BY priority DESC, discovered_at ASC
|
||||
ORDER BY post_created_at DESC, priority DESC, discovered_at ASC
|
||||
LIMIT ?
|
||||
)
|
||||
`).run(now, now, capacity).changes;
|
||||
@@ -302,15 +303,8 @@ export class CandidateQueueRepository {
|
||||
SELECT * FROM candidate_queue
|
||||
WHERE status IN (${ACTIVE_STATUSES.map(() => '?').join(', ')})
|
||||
ORDER BY
|
||||
CASE status
|
||||
WHEN 'sending' THEN 1
|
||||
WHEN 'screening' THEN 2
|
||||
WHEN 'ready' THEN 3
|
||||
WHEN 'retryable' THEN 4
|
||||
ELSE 5
|
||||
END,
|
||||
priority DESC,
|
||||
post_created_at DESC,
|
||||
priority DESC,
|
||||
discovered_at ASC
|
||||
LIMIT ?
|
||||
`).all(...ACTIVE_STATUSES, limit) as Array<Record<string, unknown>>;
|
||||
@@ -332,7 +326,7 @@ export class CandidateQueueRepository {
|
||||
const row = this.db.prepare(`
|
||||
SELECT post_id FROM candidate_queue
|
||||
WHERE status = ? AND available_at <= ? ${requirePrepared ? 'AND prepared_json IS NOT NULL' : ''}
|
||||
ORDER BY priority DESC, post_created_at DESC, discovered_at ASC
|
||||
ORDER BY post_created_at DESC, priority DESC, discovered_at ASC
|
||||
LIMIT 1
|
||||
`).get(from, now) as { post_id: string } | undefined;
|
||||
if (!row) return null;
|
||||
|
||||
Reference in new issue
Block a user