feat: defer login bootstrap updates
This commit is contained in:
parent
a246fd5417
commit
4d9f1e271d
18 changed files with 958 additions and 188 deletions
2
deploy/migrations/0052_bootstrap_update_jobs.down.sql
Normal file
2
deploy/migrations/0052_bootstrap_update_jobs.down.sql
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
DROP INDEX IF EXISTS public.user_update_events_new_message_box_idx;
|
||||
DROP TABLE IF EXISTS public.bootstrap_update_jobs;
|
||||
34
deploy/migrations/0052_bootstrap_update_jobs.up.sql
Normal file
34
deploy/migrations/0052_bootstrap_update_jobs.up.sql
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
CREATE TABLE IF NOT EXISTS public.bootstrap_update_jobs (
|
||||
id bigint GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
||||
kind character varying(32) NOT NULL,
|
||||
user_id bigint NOT NULL REFERENCES public.users(id) ON DELETE CASCADE,
|
||||
auth_key_id bigint DEFAULT 0 NOT NULL,
|
||||
session_id bigint DEFAULT 0 NOT NULL,
|
||||
message_box_id integer NOT NULL,
|
||||
status character varying(16) DEFAULT 'pending'::character varying NOT NULL,
|
||||
attempts integer DEFAULT 0 NOT NULL,
|
||||
last_error text DEFAULT ''::text NOT NULL,
|
||||
created_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
updated_at timestamp with time zone DEFAULT now() NOT NULL,
|
||||
ready_at timestamp with time zone,
|
||||
published_at timestamp with time zone,
|
||||
CONSTRAINT bootstrap_update_jobs_kind_check CHECK ((kind)::text = ANY (ARRAY[('login_message'::character varying)::text])),
|
||||
CONSTRAINT bootstrap_update_jobs_status_check CHECK ((status)::text = ANY (ARRAY[('pending'::character varying)::text, ('ready'::character varying)::text, ('publishing'::character varying)::text, ('published'::character varying)::text, ('failed'::character varying)::text])),
|
||||
CONSTRAINT bootstrap_update_jobs_message_box_fkey FOREIGN KEY (user_id, message_box_id) REFERENCES public.message_boxes(owner_user_id, box_id) ON DELETE CASCADE
|
||||
);
|
||||
|
||||
CREATE UNIQUE INDEX IF NOT EXISTS bootstrap_update_jobs_unique_login
|
||||
ON public.bootstrap_update_jobs (kind, user_id, message_box_id);
|
||||
|
||||
CREATE INDEX IF NOT EXISTS bootstrap_update_jobs_ready_idx
|
||||
ON public.bootstrap_update_jobs (COALESCE(ready_at, created_at), user_id, id)
|
||||
WHERE (status)::text = 'ready'::text;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS bootstrap_update_jobs_publishing_stale_idx
|
||||
ON public.bootstrap_update_jobs (updated_at, user_id, id)
|
||||
WHERE (status)::text = 'publishing'::text;
|
||||
|
||||
CREATE INDEX IF NOT EXISTS user_update_events_new_message_box_idx
|
||||
ON public.user_update_events (user_id, message_box_id, pts)
|
||||
WHERE (event_type)::text = 'new_message'::text
|
||||
AND message_box_id IS NOT NULL;
|
||||
Loading…
Add table
Add a link
Reference in a new issue