Clean up dead db tables

This commit is contained in:
Kira 2020-01-12 18:41:07 -08:00
parent 38427ce5ab
commit 621df484f5
4 changed files with 14 additions and 454 deletions

View File

@ -12,7 +12,6 @@ module Maintenance
ignoring_exceptions { TagAlias.update_cached_post_counts_for_all } ignoring_exceptions { TagAlias.update_cached_post_counts_for_all }
ignoring_exceptions { PostDisapproval.dmail_messages! } ignoring_exceptions { PostDisapproval.dmail_messages! }
ignoring_exceptions { Tag.clean_up_negative_post_counts! } ignoring_exceptions { Tag.clean_up_negative_post_counts! }
ignoring_exceptions { TokenBucket.prune! }
ignoring_exceptions { TagChangeRequestPruner.warn_all } ignoring_exceptions { TagChangeRequestPruner.warn_all }
ignoring_exceptions { TagChangeRequestPruner.reject_all } ignoring_exceptions { TagChangeRequestPruner.reject_all }
ignoring_exceptions { Ban.prune! } ignoring_exceptions { Ban.prune! }

View File

@ -1,41 +0,0 @@
class TokenBucket < ApplicationRecord
self.primary_key = "user_id"
belongs_to :user
def self.prune!
where("last_touched_at < ?", 1.day.ago).delete_all
end
def self.create_default(user)
TokenBucket.create(user_id: user.id, token_count: user.api_burst_limit, last_touched_at: Time.now)
end
def accept?
token_count >= 1
end
def add!
now = Time.now
TokenBucket.where(user_id: user_id).update_all(["token_count = least(token_count + (? * extract(epoch from ? - last_touched_at)), ?), last_touched_at = ?", user.api_regen_multiplier, now, user.api_burst_limit, now])
# estimate the token count to avoid reloading
self.token_count += user.api_regen_multiplier * (now - last_touched_at)
self.token_count = user.api_burst_limit if token_count > user.api_burst_limit
end
def consume!
TokenBucket.where(user_id: user_id).update_all("token_count = greatest(0, token_count - 1)")
self.token_count -= 1
end
def throttled?
add!
if accept?
consume!
return false
else
return true
end
end
end

View File

@ -0,0 +1,12 @@
class DropUnusedTables < ActiveRecord::Migration[6.0]
def change
drop_table :advertisement_hits
drop_table :advertisements
drop_table :amazon_backups
drop_table :anti_voters
drop_table :delayed_jobs
drop_table :super_voters
drop_table :tag_subscriptions
drop_table :token_buckets
end
end

View File

@ -130,142 +130,6 @@ SET default_tablespace = '';
SET default_with_oids = false; SET default_with_oids = false;
--
-- Name: advertisement_hits; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.advertisement_hits (
id integer NOT NULL,
advertisement_id integer NOT NULL,
ip_addr inet NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: advertisement_hits_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.advertisement_hits_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: advertisement_hits_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.advertisement_hits_id_seq OWNED BY public.advertisement_hits.id;
--
-- Name: advertisements; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.advertisements (
id integer NOT NULL,
referral_url text NOT NULL,
ad_type character varying NOT NULL,
status character varying NOT NULL,
hit_count integer DEFAULT 0 NOT NULL,
width integer NOT NULL,
height integer NOT NULL,
file_name character varying NOT NULL,
is_work_safe boolean DEFAULT false NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: advertisements_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.advertisements_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: advertisements_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.advertisements_id_seq OWNED BY public.advertisements.id;
--
-- Name: amazon_backups; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.amazon_backups (
id integer NOT NULL,
last_id integer,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: amazon_backups_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.amazon_backups_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: amazon_backups_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.amazon_backups_id_seq OWNED BY public.amazon_backups.id;
--
-- Name: anti_voters; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.anti_voters (
id integer NOT NULL,
user_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: anti_voters_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.anti_voters_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: anti_voters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.anti_voters_id_seq OWNED BY public.anti_voters.id;
-- --
-- Name: api_keys; Type: TABLE; Schema: public; Owner: - -- Name: api_keys; Type: TABLE; Schema: public; Owner: -
-- --
@ -684,46 +548,6 @@ CREATE SEQUENCE public.comments_id_seq
ALTER SEQUENCE public.comments_id_seq OWNED BY public.comments.id; ALTER SEQUENCE public.comments_id_seq OWNED BY public.comments.id;
--
-- Name: delayed_jobs; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.delayed_jobs (
id integer NOT NULL,
priority integer DEFAULT 0,
attempts integer DEFAULT 0,
handler text,
last_error text,
run_at timestamp without time zone,
locked_at timestamp without time zone,
failed_at timestamp without time zone,
locked_by character varying,
created_at timestamp without time zone,
updated_at timestamp without time zone,
queue character varying
);
--
-- Name: delayed_jobs_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.delayed_jobs_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: delayed_jobs_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.delayed_jobs_id_seq OWNED BY public.delayed_jobs.id;
-- --
-- Name: dmail_filters; Type: TABLE; Schema: public; Owner: - -- Name: dmail_filters; Type: TABLE; Schema: public; Owner: -
-- --
@ -2076,38 +1900,6 @@ CREATE TABLE public.schema_migrations (
); );
--
-- Name: super_voters; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.super_voters (
id integer NOT NULL,
user_id integer,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL
);
--
-- Name: super_voters_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.super_voters_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: super_voters_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.super_voters_id_seq OWNED BY public.super_voters.id;
-- --
-- Name: tag_aliases; Type: TABLE; Schema: public; Owner: - -- Name: tag_aliases; Type: TABLE; Schema: public; Owner: -
-- --
@ -2224,44 +2016,6 @@ CREATE SEQUENCE public.tag_rel_undos_id_seq
ALTER SEQUENCE public.tag_rel_undos_id_seq OWNED BY public.tag_rel_undos.id; ALTER SEQUENCE public.tag_rel_undos_id_seq OWNED BY public.tag_rel_undos.id;
--
-- Name: tag_subscriptions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.tag_subscriptions (
id integer NOT NULL,
creator_id integer NOT NULL,
name character varying NOT NULL,
tag_query text NOT NULL,
post_ids text NOT NULL,
is_public boolean DEFAULT true NOT NULL,
last_accessed_at timestamp without time zone,
is_opted_in boolean DEFAULT false NOT NULL,
created_at timestamp without time zone,
updated_at timestamp without time zone
);
--
-- Name: tag_subscriptions_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
CREATE SEQUENCE public.tag_subscriptions_id_seq
AS integer
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--
-- Name: tag_subscriptions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--
ALTER SEQUENCE public.tag_subscriptions_id_seq OWNED BY public.tag_subscriptions.id;
-- --
-- Name: tag_type_versions; Type: TABLE; Schema: public; Owner: - -- Name: tag_type_versions; Type: TABLE; Schema: public; Owner: -
-- --
@ -2418,17 +2172,6 @@ CREATE SEQUENCE public.tickets_id_seq
ALTER SEQUENCE public.tickets_id_seq OWNED BY public.tickets.id; ALTER SEQUENCE public.tickets_id_seq OWNED BY public.tickets.id;
--
-- Name: token_buckets; Type: TABLE; Schema: public; Owner: -
--
CREATE UNLOGGED TABLE public.token_buckets (
user_id integer,
last_touched_at timestamp without time zone NOT NULL,
token_count real NOT NULL
);
-- --
-- Name: upload_whitelists; Type: TABLE; Schema: public; Owner: - -- Name: upload_whitelists; Type: TABLE; Schema: public; Owner: -
-- --
@ -2817,34 +2560,6 @@ CREATE SEQUENCE public.wiki_pages_id_seq
ALTER SEQUENCE public.wiki_pages_id_seq OWNED BY public.wiki_pages.id; ALTER SEQUENCE public.wiki_pages_id_seq OWNED BY public.wiki_pages.id;
--
-- Name: advertisement_hits id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.advertisement_hits ALTER COLUMN id SET DEFAULT nextval('public.advertisement_hits_id_seq'::regclass);
--
-- Name: advertisements id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.advertisements ALTER COLUMN id SET DEFAULT nextval('public.advertisements_id_seq'::regclass);
--
-- Name: amazon_backups id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.amazon_backups ALTER COLUMN id SET DEFAULT nextval('public.amazon_backups_id_seq'::regclass);
--
-- Name: anti_voters id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.anti_voters ALTER COLUMN id SET DEFAULT nextval('public.anti_voters_id_seq'::regclass);
-- --
-- Name: api_keys id; Type: DEFAULT; Schema: public; Owner: - -- Name: api_keys id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -2922,13 +2637,6 @@ ALTER TABLE ONLY public.comment_votes ALTER COLUMN id SET DEFAULT nextval('publi
ALTER TABLE ONLY public.comments ALTER COLUMN id SET DEFAULT nextval('public.comments_id_seq'::regclass); ALTER TABLE ONLY public.comments ALTER COLUMN id SET DEFAULT nextval('public.comments_id_seq'::regclass);
--
-- Name: delayed_jobs id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.delayed_jobs ALTER COLUMN id SET DEFAULT nextval('public.delayed_jobs_id_seq'::regclass);
-- --
-- Name: dmail_filters id; Type: DEFAULT; Schema: public; Owner: - -- Name: dmail_filters id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -3181,13 +2889,6 @@ ALTER TABLE ONLY public.posts ALTER COLUMN change_seq SET DEFAULT nextval('publi
ALTER TABLE ONLY public.saved_searches ALTER COLUMN id SET DEFAULT nextval('public.saved_searches_id_seq'::regclass); ALTER TABLE ONLY public.saved_searches ALTER COLUMN id SET DEFAULT nextval('public.saved_searches_id_seq'::regclass);
--
-- Name: super_voters id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.super_voters ALTER COLUMN id SET DEFAULT nextval('public.super_voters_id_seq'::regclass);
-- --
-- Name: tag_aliases id; Type: DEFAULT; Schema: public; Owner: - -- Name: tag_aliases id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -3209,13 +2910,6 @@ ALTER TABLE ONLY public.tag_implications ALTER COLUMN id SET DEFAULT nextval('pu
ALTER TABLE ONLY public.tag_rel_undos ALTER COLUMN id SET DEFAULT nextval('public.tag_rel_undos_id_seq'::regclass); ALTER TABLE ONLY public.tag_rel_undos ALTER COLUMN id SET DEFAULT nextval('public.tag_rel_undos_id_seq'::regclass);
--
-- Name: tag_subscriptions id; Type: DEFAULT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tag_subscriptions ALTER COLUMN id SET DEFAULT nextval('public.tag_subscriptions_id_seq'::regclass);
-- --
-- Name: tag_type_versions id; Type: DEFAULT; Schema: public; Owner: - -- Name: tag_type_versions id; Type: DEFAULT; Schema: public; Owner: -
-- --
@ -3307,38 +3001,6 @@ ALTER TABLE ONLY public.wiki_page_versions ALTER COLUMN id SET DEFAULT nextval('
ALTER TABLE ONLY public.wiki_pages ALTER COLUMN id SET DEFAULT nextval('public.wiki_pages_id_seq'::regclass); ALTER TABLE ONLY public.wiki_pages ALTER COLUMN id SET DEFAULT nextval('public.wiki_pages_id_seq'::regclass);
--
-- Name: advertisement_hits advertisement_hits_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.advertisement_hits
ADD CONSTRAINT advertisement_hits_pkey PRIMARY KEY (id);
--
-- Name: advertisements advertisements_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.advertisements
ADD CONSTRAINT advertisements_pkey PRIMARY KEY (id);
--
-- Name: amazon_backups amazon_backups_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.amazon_backups
ADD CONSTRAINT amazon_backups_pkey PRIMARY KEY (id);
--
-- Name: anti_voters anti_voters_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.anti_voters
ADD CONSTRAINT anti_voters_pkey PRIMARY KEY (id);
-- --
-- Name: api_keys api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: api_keys api_keys_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -3435,14 +3097,6 @@ ALTER TABLE ONLY public.comments
ADD CONSTRAINT comments_pkey PRIMARY KEY (id); ADD CONSTRAINT comments_pkey PRIMARY KEY (id);
--
-- Name: delayed_jobs delayed_jobs_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.delayed_jobs
ADD CONSTRAINT delayed_jobs_pkey PRIMARY KEY (id);
-- --
-- Name: dmail_filters dmail_filters_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: dmail_filters dmail_filters_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -3733,14 +3387,6 @@ ALTER TABLE ONLY public.schema_migrations
ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version); ADD CONSTRAINT schema_migrations_pkey PRIMARY KEY (version);
--
-- Name: super_voters super_voters_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.super_voters
ADD CONSTRAINT super_voters_pkey PRIMARY KEY (id);
-- --
-- Name: tag_aliases tag_aliases_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: tag_aliases tag_aliases_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -3765,14 +3411,6 @@ ALTER TABLE ONLY public.tag_rel_undos
ADD CONSTRAINT tag_rel_undos_pkey PRIMARY KEY (id); ADD CONSTRAINT tag_rel_undos_pkey PRIMARY KEY (id);
--
-- Name: tag_subscriptions tag_subscriptions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.tag_subscriptions
ADD CONSTRAINT tag_subscriptions_pkey PRIMARY KEY (id);
-- --
-- Name: tag_type_versions tag_type_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: - -- Name: tag_type_versions tag_type_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
-- --
@ -3877,27 +3515,6 @@ ALTER TABLE ONLY public.wiki_pages
ADD CONSTRAINT wiki_pages_pkey PRIMARY KEY (id); ADD CONSTRAINT wiki_pages_pkey PRIMARY KEY (id);
--
-- Name: index_advertisement_hits_on_advertisement_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_advertisement_hits_on_advertisement_id ON public.advertisement_hits USING btree (advertisement_id);
--
-- Name: index_advertisement_hits_on_created_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_advertisement_hits_on_created_at ON public.advertisement_hits USING btree (created_at);
--
-- Name: index_advertisements_on_ad_type; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_advertisements_on_ad_type ON public.advertisements USING btree (ad_type);
-- --
-- Name: index_api_keys_on_key; Type: INDEX; Schema: public; Owner: - -- Name: index_api_keys_on_key; Type: INDEX; Schema: public; Owner: -
-- --
@ -4129,13 +3746,6 @@ CREATE INDEX index_comments_on_creator_ip_addr ON public.comments USING btree (c
CREATE INDEX index_comments_on_post_id ON public.comments USING btree (post_id); CREATE INDEX index_comments_on_post_id ON public.comments USING btree (post_id);
--
-- Name: index_delayed_jobs_on_run_at; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_delayed_jobs_on_run_at ON public.delayed_jobs USING btree (run_at);
-- --
-- Name: index_dmail_filters_on_user_id; Type: INDEX; Schema: public; Owner: - -- Name: index_dmail_filters_on_user_id; Type: INDEX; Schema: public; Owner: -
-- --
@ -4808,20 +4418,6 @@ CREATE INDEX index_tag_implications_on_forum_post_id ON public.tag_implications
CREATE INDEX index_tag_rel_undos_on_tag_rel_type_and_tag_rel_id ON public.tag_rel_undos USING btree (tag_rel_type, tag_rel_id); CREATE INDEX index_tag_rel_undos_on_tag_rel_type_and_tag_rel_id ON public.tag_rel_undos USING btree (tag_rel_type, tag_rel_id);
--
-- Name: index_tag_subscriptions_on_creator_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_tag_subscriptions_on_creator_id ON public.tag_subscriptions USING btree (creator_id);
--
-- Name: index_tag_subscriptions_on_name; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX index_tag_subscriptions_on_name ON public.tag_subscriptions USING btree (name);
-- --
-- Name: index_tag_type_versions_on_creator_id; Type: INDEX; Schema: public; Owner: - -- Name: index_tag_type_versions_on_creator_id; Type: INDEX; Schema: public; Owner: -
-- --
@ -4864,13 +4460,6 @@ CREATE INDEX index_tags_on_name_prefix ON public.tags USING gin (regexp_replace(
CREATE INDEX index_tags_on_name_trgm ON public.tags USING gin (name public.gin_trgm_ops); CREATE INDEX index_tags_on_name_trgm ON public.tags USING gin (name public.gin_trgm_ops);
--
-- Name: index_token_buckets_on_user_id; Type: INDEX; Schema: public; Owner: -
--
CREATE UNIQUE INDEX index_token_buckets_on_user_id ON public.token_buckets USING btree (user_id);
-- --
-- Name: index_uploads_on_referer_url; Type: INDEX; Schema: public; Owner: - -- Name: index_uploads_on_referer_url; Type: INDEX; Schema: public; Owner: -
-- --
@ -5338,6 +4927,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20191006143246'), ('20191006143246'),
('20191013233447'), ('20191013233447'),
('20191116032230'), ('20191116032230'),
('20191231162515'); ('20191231162515'),
('20200113022639');