Only crosspost link if still rank 1 after 1 hour

This commit is contained in:
ekzyis 2024-03-31 03:48:51 +02:00
parent 1416550be9
commit 7786a7f6da
1 changed files with 4 additions and 3 deletions

7
sn.go
View File

@ -19,12 +19,13 @@ func CurateContentForStackerNews() (*[]Story, error) {
if rows, err = db.Query(` if rows, err = db.Query(`
SELECT t.id, time, title, url, author, score, ndescendants SELECT t.id, time, title, url, author, score, ndescendants
FROM ( FROM (
SELECT id, MAX(created_at) AS created_at FROM hn_items SELECT id, MIN(created_at) AS start, MAX(created_at) AS end
FROM hn_items
WHERE rank = 1 AND id NOT IN (SELECT hn_id FROM sn_items) AND length(title) >= 5 WHERE rank = 1 AND id NOT IN (SELECT hn_id FROM sn_items) AND length(title) >= 5
GROUP BY id GROUP BY id
ORDER BY time ASC HAVING unixepoch(end) - unixepoch(start) >= 3600 ORDER BY time ASC
LIMIT 1 LIMIT 1
) t JOIN hn_items ON t.id = hn_items.id AND t.created_at = hn_items.created_at; ) t JOIN hn_items ON t.id = hn_items.id AND t.end = hn_items.created_at;
`); err != nil { `); err != nil {
err = fmt.Errorf("error querying hn_items: %w", err) err = fmt.Errorf("error querying hn_items: %w", err)
return nil, err return nil, err