Filter unattributed successful messages

This commit is contained in:
jjbrunton committed 2026-08-08 18:28:46 +01:00
1 parent 2c100d72b6
commit 7bcdbe236a
3 files changed
+62 -1

No files matched your search

+17
View File
@@ -664,6 +664,7 @@ export class MessagesRepository {
export class SuccessfulMessagesRepository {
private insertStmt: Database.Statement;
private getRecentStmt: Database.Statement;
private getAttributedRecentStmt: Database.Statement;
private getBySubredditStmt: Database.Statement;
private countStmt: Database.Statement;
private existsByMessageStmt: Database.Statement;
@@ -678,6 +679,17 @@ export class SuccessfulMessagesRepository {
SELECT * FROM successful_messages ORDER BY created_at DESC, id DESC LIMIT ?
`);
this.getAttributedRecentStmt = db.prepare(`
SELECT successful_messages.*
FROM successful_messages
LEFT JOIN sent_messages sm ON sm.id = successful_messages.sent_message_id
WHERE successful_messages.subreddit IS NOT NULL
OR sm.post_id IS NOT NULL
OR sm.strategy_id IS NOT NULL
ORDER BY successful_messages.created_at DESC, successful_messages.id DESC
LIMIT ?
`);
// Get examples prioritizing same subreddit, then falling back to others
this.getBySubredditStmt = db.prepare(`
SELECT *,
@@ -722,6 +734,11 @@ export class SuccessfulMessagesRepository {
return rows.map((row) => this.mapRow(row));
}
getAttributedRecent(limit: number = 5): SuccessfulMessageRecord[] {
const rows = this.getAttributedRecentStmt.all(limit) as Record<string, unknown>[];
return rows.map((row) => this.mapRow(row));
}
getWeightedExamples(subreddit: string | null, limit: number = 3): SuccessfulMessageRecord[] {
if (subreddit) {
const rows = this.getBySubredditStmt.all(subreddit, limit) as Record<string, unknown>[];
+1 -1
View File
@@ -50,7 +50,7 @@ export function createStatsRouter(ctx: WebContext): Router {
});
router.get('/successful', (_req, res) => {
res.json(ctx.repos.successful.getRecent(10));
res.json(ctx.repos.successful.getAttributedRecent(10));
});
return router;