|
|
|
|
@@ -33,10 +33,14 @@ func InsertStory(s *Story) error {
|
|
|
|
|
if s.Paywalled {
|
|
|
|
|
paywalled = 1
|
|
|
|
|
}
|
|
|
|
|
var publishedAt any
|
|
|
|
|
if s.PublishedAt > 0 {
|
|
|
|
|
publishedAt = s.PublishedAt
|
|
|
|
|
}
|
|
|
|
|
_, err := Get().Exec(
|
|
|
|
|
`INSERT INTO stories (guid, headline, lede, image_url, article_url, url_canonical, headline_norm, source, platforms, channel, classified, paywalled, seen_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
|
|
s.GUID, s.Headline, s.Lede, s.ImageURL, s.ArticleURL, nullIfEmpty(s.URLCanonical), nullIfEmpty(s.HeadlineNorm), s.Source, s.Platforms, s.Channel, classified, paywalled, s.SeenAt,
|
|
|
|
|
`INSERT INTO stories (guid, headline, lede, image_url, article_url, url_canonical, headline_norm, source, platforms, channel, classified, paywalled, seen_at, published_at)
|
|
|
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
|
|
|
s.GUID, s.Headline, s.Lede, s.ImageURL, s.ArticleURL, nullIfEmpty(s.URLCanonical), nullIfEmpty(s.HeadlineNorm), s.Source, s.Platforms, s.Channel, classified, paywalled, s.SeenAt, publishedAt,
|
|
|
|
|
)
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
@@ -185,7 +189,7 @@ func GetNewestPostableStory(source string) (*Story, error) {
|
|
|
|
|
AND channel IS NOT NULL
|
|
|
|
|
AND channel NOT IN ('_discarded', '_duplicate')
|
|
|
|
|
AND guid NOT IN (SELECT guid FROM post_log)
|
|
|
|
|
ORDER BY seen_at DESC
|
|
|
|
|
ORDER BY COALESCE(published_at, seen_at) DESC
|
|
|
|
|
LIMIT 1`, source)
|
|
|
|
|
var s Story
|
|
|
|
|
if err := row.Scan(&s.GUID, &s.Headline, &s.Lede, &s.ImageURL, &s.ArticleURL, &s.Source, &s.Platforms, &s.Channel, &s.SeenAt); err != nil {
|
|
|
|
|
@@ -208,7 +212,7 @@ func GetNewestPostableStoryByChannel(channel string) (*Story, error) {
|
|
|
|
|
WHERE classified = 1
|
|
|
|
|
AND channel = ?
|
|
|
|
|
AND guid NOT IN (SELECT guid FROM post_log)
|
|
|
|
|
ORDER BY seen_at DESC
|
|
|
|
|
ORDER BY COALESCE(published_at, seen_at) DESC
|
|
|
|
|
LIMIT 1`, channel)
|
|
|
|
|
var s Story
|
|
|
|
|
if err := row.Scan(&s.GUID, &s.Headline, &s.Lede, &s.ImageURL, &s.ArticleURL, &s.Source, &s.Platforms, &s.Channel, &s.SeenAt); err != nil {
|
|
|
|
|
@@ -230,7 +234,7 @@ func ListClassifiedByChannel(channel string, limit, offset int) ([]Story, error)
|
|
|
|
|
FROM stories s
|
|
|
|
|
WHERE s.classified = 1
|
|
|
|
|
AND s.channel = ?
|
|
|
|
|
ORDER BY s.seen_at DESC
|
|
|
|
|
ORDER BY COALESCE(s.published_at, s.seen_at) DESC
|
|
|
|
|
LIMIT ? OFFSET ?`, channel, limit, offset)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
@@ -257,7 +261,7 @@ func ListAllClassified(limit, offset int) ([]Story, error) {
|
|
|
|
|
WHERE s.classified = 1
|
|
|
|
|
AND s.channel IS NOT NULL
|
|
|
|
|
AND s.channel NOT IN ('_discarded', '_duplicate')
|
|
|
|
|
ORDER BY s.seen_at DESC
|
|
|
|
|
ORDER BY COALESCE(s.published_at, s.seen_at) DESC
|
|
|
|
|
LIMIT ? OFFSET ?`, limit, offset)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return nil, err
|
|
|
|
|
|