2
0
mirror of https://github.com/moebooru/moebooru synced 2025-08-22 01:47:48 +00:00

Add index for post warehousing tasks

This commit is contained in:
nanaya 2020-11-03 23:11:35 +09:00
parent 7e30845bc2
commit b6e61fc2b0
3 changed files with 16 additions and 0 deletions

View File

@ -137,6 +137,7 @@ class PostFrames < ApplicationRecord
# Warehouse frames. Only frames which are created and finalized will be warehoused.
def self.warehouse_frames(update_status = nil)
# Find a post with frames that need warehousing.
# This SQL is designed to use the post_frames_for_warehouse.
post = Post.find_by("frames = frames_pending AND frames <> '' AND NOT frames_warehoused")
return false if post.nil?

View File

@ -0,0 +1,7 @@
class AddPostWarehouseIndex < ActiveRecord::Migration[6.0]
def change
add_index :posts, :id,
name: 'post_frames_for_warehouse',
where: "frames = frames_pending AND frames <> '' AND NOT frames_warehoused"
end
end

View File

@ -2639,6 +2639,13 @@ CREATE INDEX pools_posts_post_id_idx ON public.pools_posts USING btree (post_id)
CREATE INDEX pools_user_id_idx ON public.pools USING btree (user_id);
--
-- Name: post_frames_for_warehouse; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX post_frames_for_warehouse ON public.posts USING btree (id) WHERE ((frames = frames_pending) AND (frames <> ''::text) AND (NOT frames_warehoused));
--
-- Name: post_frames_out_of_date; Type: INDEX; Schema: public; Owner: -
--
@ -3400,6 +3407,7 @@ INSERT INTO "schema_migrations" (version) VALUES
('20190817070727'),
('20191110172526'),
('20200908180652'),
('20201103140508'),
('21'),
('22'),
('23'),