From 09d5457436ffaf5eabfd965281393e0a382cecfb Mon Sep 17 00:00:00 2001 From: Andre Medeiros Date: Sat, 21 May 2022 13:08:30 -0400 Subject: [PATCH] fix migrations --- internal/worker/notifications.go | 8 ++++---- migrations/000001_create_accounts.up.sql | 16 +++++----------- migrations/000004_create_subreddits.up.sql | 2 +- migrations/000005_create_users.up.sql | 2 +- migrations/000006_create_watchers.up.sql | 6 +++--- 5 files changed, 14 insertions(+), 20 deletions(-) diff --git a/internal/worker/notifications.go b/internal/worker/notifications.go index 8ab3757..06d5a7b 100644 --- a/internal/worker/notifications.go +++ b/internal/worker/notifications.go @@ -22,9 +22,9 @@ import ( ) const ( - backoff = 5 // How long we wait in between checking for notifications, in seconds - pollDuration = 5 * time.Millisecond - rate = 0.1 + checkInterval = 5 * time.Second // How long we wait in between checking for notifications, in seconds + pollDuration = 5 * time.Millisecond + rate = 0.1 postReplyNotificationTitleFormat = "%s to %s" commentReplyNotificationTitleFormat = "%s in %s" @@ -239,7 +239,7 @@ func (nc *notificationsConsumer) Consume(delivery rmq.Delivery) { // Only update delay on accounts we can actually check, otherwise it skews // the numbers too much. if !newAccount { - latency := now.Sub(previousNextCheck) - backoff*time.Second + latency := now.Sub(previousNextCheck) - checkInterval _ = nc.statsd.Histogram("apollo.queue.delay", float64(latency.Milliseconds()), []string{}, rate) } diff --git a/migrations/000001_create_accounts.up.sql b/migrations/000001_create_accounts.up.sql index edac32c..10a6077 100644 --- a/migrations/000001_create_accounts.up.sql +++ b/migrations/000001_create_accounts.up.sql @@ -2,19 +2,13 @@ CREATE TABLE accounts ( id SERIAL PRIMARY KEY, + reddit_account_id character varying(32) DEFAULT ''::character varying, username character varying(20) DEFAULT ''::character varying UNIQUE, access_token character varying(64) DEFAULT ''::character varying, refresh_token character varying(64) DEFAULT ''::character varying, - expires_at integer DEFAULT 0, + token_expires_at timestamp without time zone, last_message_id character varying(32) DEFAULT ''::character varying, - device_count integer DEFAULT 0, - last_checked_at double precision DEFAULT '0'::double precision, - last_enqueued_at double precision DEFAULT '0'::double precision, - account_id character varying(32) DEFAULT ''::character varying, - last_unstuck_at double precision DEFAULT '0'::double precision + next_notification_check_at timestamp without time zone, + next_stuck_notification_check_at timestamp without time zone, + check_count integer DEFAULT 0 ); - --- Indices ------------------------------------------------------- - -CREATE INDEX accounts_last_checked_at_idx ON accounts(last_checked_at float8_ops); - diff --git a/migrations/000004_create_subreddits.up.sql b/migrations/000004_create_subreddits.up.sql index 15b76c6..bfb7b93 100644 --- a/migrations/000004_create_subreddits.up.sql +++ b/migrations/000004_create_subreddits.up.sql @@ -4,6 +4,6 @@ CREATE TABLE subreddits ( id SERIAL PRIMARY KEY, subreddit_id character varying(32) DEFAULT ''::character varying UNIQUE, name character varying(32) DEFAULT ''::character varying, - last_checked_at double precision DEFAULT '0'::double precision + next_check_at timestamp without time zone ); diff --git a/migrations/000005_create_users.up.sql b/migrations/000005_create_users.up.sql index 7663437..6a0df43 100644 --- a/migrations/000005_create_users.up.sql +++ b/migrations/000005_create_users.up.sql @@ -4,6 +4,6 @@ CREATE TABLE users ( id SERIAL PRIMARY KEY, user_id character varying(32) DEFAULT ''::character varying UNIQUE, name character varying(32) DEFAULT ''::character varying, - last_checked_at double precision DEFAULT '0'::double precision + next_check_at timestamp without time zone ); diff --git a/migrations/000006_create_watchers.up.sql b/migrations/000006_create_watchers.up.sql index 9859886..48268a6 100644 --- a/migrations/000006_create_watchers.up.sql +++ b/migrations/000006_create_watchers.up.sql @@ -2,17 +2,17 @@ CREATE TABLE watchers ( id SERIAL PRIMARY KEY, + created_at timestamp without time zone, + last_notified_at timestamp without time zone, device_id integer REFERENCES devices(id) ON DELETE CASCADE, + account_id integer REFERENCES accounts(id) ON DELETE CASCADE, watchee_id integer, upvotes integer DEFAULT 0, keyword character varying(32) DEFAULT ''::character varying, flair character varying(32) DEFAULT ''::character varying, domain character varying(32) DEFAULT ''::character varying, - account_id integer REFERENCES accounts(id) ON DELETE CASCADE, - created_at double precision DEFAULT '0'::double precision, hits integer DEFAULT 0, type integer DEFAULT 0, - last_notified_at double precision DEFAULT '0'::double precision, label character varying(64) DEFAULT ''::character varying, author character varying(32) DEFAULT ''::character varying, subreddit character varying(32) DEFAULT ''::character varying