Lines of
rsstg.sql
from check-in 84130ab6bf
that are changed by the sequence of edits moving toward
check-in ebe7c281a5:
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 not null);
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_scrape not null timestamptz default now(),
16: enabled boolean not null default false,
17: iv_hash text,
18: owner bigint not null);
19: create unique index rsstg_source__source_id on rsstg_source(source_id);
20: create unique index rsstg_source__channel_id__owner on rsstg_source(channel_id, owner);
21: create index rsstg_source__owner on rsstg_source(owner);
22:
23: create table rsstg_post (
24: source_id integer not null,
25: date int not null,
26: url text not null,
27: hour smallint not null generated always as (extract('hour' from posted)) stored,
28: FOREIGN KEY (source_id) REFERENCES rsstg_source(source_id)
29: );
30: create unique index rsstg_post__url on rsstg_post(url);
31: create index rsstg_post__hour on rsstg_post(hour);
32: create index rsstg_post__posted_hour on rsstg_post(posted,hour);
33:
34: create or replace view rsstg_order as
84130ab6bf 2020-11-20 35: select source_id, coalesce(last_scrape + make_interval(0,0,0,0,0,(60 / (coalesce(activity, 1)/7 + 1) )::integer), now() - interval '1 minute') as next_fetch
36: from rsstg_source natural left join
37: (select source_id, count(*) as activity
38: from rsstg_post where
39: hour = extract('hour' from now())::smallint
40: and posted > now() - interval '7 days'
41: group by source_id) as act
42: where enabled
43: order by next_fetch;