@@ -23,11 +23,13 @@ export function clearCache(): void {
2323const Q_FEED = `
2424SELECT
2525 id, channel, title, text, url,
26- extract(epoch from date::timestamp)::integer as date
26+ extract(epoch from date::timestamp)::integer as date,
27+ extract(epoch from until::timestamp)::integer as until
2728FROM news
2829WHERE news.date <= NOW()
2930 AND hide IS NOT TRUE
3031 AND channel != '${ EVENT_CHANNEL } '
32+ AND (until IS NULL OR until > NOW())
3133ORDER BY date DESC
3234LIMIT 100` ;
3335
@@ -40,7 +42,8 @@ export async function getFeedData(): Promise<NewsItem[]> {
4042const Q_BY_ID = `
4143SELECT
4244 id, channel, title, text, url, hide, tags,
43- extract(epoch from date::timestamptz)::INTEGER as date
45+ extract(epoch from date::timestamptz)::INTEGER as date,
46+ extract(epoch from until::timestamptz)::INTEGER as until
4447FROM news
4548WHERE id = $1` ;
4649
@@ -56,7 +59,9 @@ const Q_BY_ID_USER = `
5659SELECT
5760 id, channel, title, text, url, hide, tags, history,
5861 date >= NOW() as future,
59- extract(epoch from date::timestamptz)::INTEGER as date
62+ until IS NOT NULL AND until <= NOW() as expired,
63+ extract(epoch from date::timestamptz)::INTEGER as date,
64+ extract(epoch from until::timestamptz)::INTEGER as until
6065FROM news
6166WHERE id = $1` ;
6267
@@ -68,6 +73,7 @@ WHERE date >= (SELECT date FROM news WHERE id = $1)
6873 AND hide IS NOT TRUE
6974 AND date < NOW()
7075 AND channel != '${ EVENT_CHANNEL } '
76+ AND (until IS NULL OR until > NOW())
7177ORDER BY date ASC, id ASC
7278LIMIT 1` ;
7379
@@ -79,6 +85,7 @@ WHERE date <= (SELECT date FROM news WHERE id = $1)
7985 AND hide IS NOT TRUE
8086 AND date < NOW()
8187 AND channel != '${ EVENT_CHANNEL } '
88+ AND (until IS NULL OR until > NOW())
8289ORDER BY date DESC, id DESC
8390LIMIT 1` ;
8491
@@ -104,7 +111,9 @@ const Q_INDEX = `
104111SELECT
105112 id, channel, title, text, url, hide, tags,
106113 date >= NOW() as future,
107- extract(epoch from date::timestamptz)::INTEGER as date
114+ until IS NOT NULL AND until <= NOW() as expired,
115+ extract(epoch from date::timestamptz)::INTEGER as date,
116+ extract(epoch from until::timestamptz)::INTEGER as until
108117FROM news
109118 WHERE channel <> '${ EVENT_CHANNEL } '
110119ORDER BY date DESC
@@ -122,11 +131,13 @@ export async function getIndex(
122131const Q_MOST_RECENT = `
123132SELECT
124133 id, channel, title, tags,
125- extract(epoch from date::timestamptz)::INTEGER as date
134+ extract(epoch from date::timestamptz)::INTEGER as date,
135+ extract(epoch from until::timestamptz)::INTEGER as until
126136FROM news
127137WHERE date <= NOW()
128138 AND hide IS NOT TRUE
129139 AND channel != '${ EVENT_CHANNEL } '
140+ AND (until IS NULL OR until > NOW())
130141ORDER BY date DESC
131142LIMIT 1` ;
132143
@@ -137,11 +148,13 @@ export async function getMostRecentNews(): Promise<RecentHeadline | null> {
137148const Q_RECENT = `
138149SELECT
139150 id, channel, title, tags,
140- extract(epoch from date::timestamptz)::INTEGER as date
151+ extract(epoch from date::timestamptz)::INTEGER as date,
152+ extract(epoch from until::timestamptz)::INTEGER as until
141153FROM news
142154WHERE date <= NOW()
143155 AND channel != '${ EVENT_CHANNEL } '
144156 AND hide IS NOT TRUE
157+ AND (until IS NULL OR until > NOW())
145158ORDER BY date DESC
146159LIMIT $1` ;
147160
@@ -158,11 +171,13 @@ export async function getRecentHeadlines(
158171const Q_UPCOMING_NEWS_CHANNEL_ITEMS = `
159172SELECT
160173 id, channel, title, text, url, tags,
161- extract(epoch from date::timestamp)::integer as date
174+ extract(epoch from date::timestamp)::integer as date,
175+ extract(epoch from until::timestamp)::integer as until
162176FROM news
163177WHERE date >= NOW()
164178 AND channel = $1
165179 AND hide IS NOT TRUE
180+ AND (until IS NULL OR until > NOW())
166181ORDER BY date
167182LIMIT 100` ;
168183
@@ -176,11 +191,13 @@ export async function getUpcomingNewsChannelItems(
176191const Q_PAST_NEWS_CHANNEL_ITEMS = `
177192SELECT
178193 id, channel, title, text, url, tags,
179- extract(epoch from date::timestamp)::integer as date
194+ extract(epoch from date::timestamp)::integer as date,
195+ extract(epoch from until::timestamp)::integer as until
180196FROM news
181197WHERE date <= NOW()
182198 AND channel = $1
183199 AND hide IS NOT TRUE
200+ AND (until IS NULL OR until > NOW())
184201ORDER BY date DESC
185202LIMIT 100` ;
186203
0 commit comments