Origin for each line in
rsstg.sql
from check-in 0191d490fe:
61df933942 2020-11-18 arcade: create table rsstg_updates (owner integer, update jsonb);
61df933942 2020-11-18 arcade:
61df933942 2020-11-18 arcade: create unique index rsstg_updates__id on rsstg_updates(update->>'update_id');
61df933942 2020-11-18 arcade:
61df933942 2020-11-18 arcade: -- create table rsstg_users (id integer);
61df933942 2020-11-18 arcade: create table rsstg_channel (
61df933942 2020-11-18 arcade: channel_id bigint primary key,
61df933942 2020-11-18 arcade: username text);
61df933942 2020-11-18 arcade: create unique index rsstg_channel__username on rsstg_channel(username);
61df933942 2020-11-18 arcade:
61df933942 2020-11-18 arcade: create table rsstg_source (
61df933942 2020-11-18 arcade: source_id serial,
61df933942 2020-11-18 arcade: channel_id integer not null,
61df933942 2020-11-18 arcade: url text not null,
61df933942 2020-11-18 arcade: last_fetch timestamptz,
61df933942 2020-11-18 arcade: last_scrape timestamptz default now(),
61df933942 2020-11-18 arcade: enabled boolean default false,
61df933942 2020-11-18 arcade: iv_hash text,
61df933942 2020-11-18 arcade: owner bigint not null);
61df933942 2020-11-18 arcade: create unique index rsstg_source__source_id on rsstg_source(source_id);
61df933942 2020-11-18 arcade: create unique index rsstg_source__channel_id__owner on rsstg_source(channel_id, owner);
61df933942 2020-11-18 arcade: create index rsstg_source__owner on rsstg_source(owner);
61df933942 2020-11-18 arcade:
61df933942 2020-11-18 arcade: create table rsstg_post (
61df933942 2020-11-18 arcade: source_id integer not null,
61df933942 2020-11-18 arcade: date int not null,
61df933942 2020-11-18 arcade: url text not null,
61df933942 2020-11-18 arcade: hour smallint generated always as (extract('hour' from posted)) stored,
61df933942 2020-11-18 arcade: FOREIGN KEY (source_id) REFERENCES rsstg_source(source_id)
61df933942 2020-11-18 arcade: );
61df933942 2020-11-18 arcade: create unique index rsstg_post__url on rsstg_post(url);
61df933942 2020-11-18 arcade: create index rsstg_post__hour on rsstg_post(hour);
0191d490fe 2020-11-18 arcade: create index rsstg_post__posted_hour on rsstg_post(posted,hour);
61df933942 2020-11-18 arcade:
61df933942 2020-11-18 arcade: create or replace view rsstg_order as
0191d490fe 2020-11-18 arcade: 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
61df933942 2020-11-18 arcade: from rsstg_source natural left join
61df933942 2020-11-18 arcade: (select source_id, count(*) as activity
61df933942 2020-11-18 arcade: from rsstg_post where
61df933942 2020-11-18 arcade: hour = extract('hour' from now())
0191d490fe 2020-11-18 arcade: and posted > now() - interval '7 days'
61df933942 2020-11-18 arcade: group by source_id) as act
61df933942 2020-11-18 arcade: where enabled
61df933942 2020-11-18 arcade: order by next_fetch;