Lines of
rsstg.sql
from check-in 0191d490fe
that are changed by the sequence of edits moving toward
check-in 21d16a0993:
1: create table rsstg_updates (owner integer, update jsonb);
2:
3: create unique index rsstg_updates__id on rsstg_updates(update->>'update_id');
4:
5: -- create table rsstg_users (id integer);
6: create table rsstg_channel (
7: channel_id bigint primary key,
8: username text);
9: create unique index rsstg_channel__username on rsstg_channel(username);
10:
11: create table rsstg_source (
12: source_id serial,
13: channel_id integer not null,
14: url text not null,
15: last_fetch timestamptz,
16: last_scrape timestamptz default now(),
17: enabled boolean default false,
18: iv_hash text,
19: owner bigint not null);
20: create unique index rsstg_source__source_id on rsstg_source(source_id);
21: create unique index rsstg_source__channel_id__owner on rsstg_source(channel_id, owner);
22: create index rsstg_source__owner on rsstg_source(owner);
23:
24: create table rsstg_post (
25: source_id integer not null,
26: date int not null,
27: url text not null,
28: hour smallint generated always as (extract('hour' from posted)) stored,
29: FOREIGN KEY (source_id) REFERENCES rsstg_source(source_id)
30: );
31: create unique index rsstg_post__url on rsstg_post(url);
32: create index rsstg_post__hour on rsstg_post(hour);
33: create index rsstg_post__posted_hour on rsstg_post(posted,hour);
34:
35: create or replace view rsstg_order as
0191d490fe 2020-11-18 36: select source_id, coalesce(last_scrape + make_interval(0,0,0,0,0,(420 / coalesce(activity , 1))::integer), now() - interval '1 minute') as next_fetch
37: from rsstg_source natural left join
38: (select source_id, count(*) as activity
39: from rsstg_post where
40: hour = extract('hour' from now())
41: and posted > now() - interval '7 days'
42: group by source_id) as act
43: where enabled
44: order by next_fetch;