diff --git a/app/controllers/artists_controller.rb b/app/controllers/artists_controller.rb index e0790d171..97fd01578 100644 --- a/app/controllers/artists_controller.rb +++ b/app/controllers/artists_controller.rb @@ -44,7 +44,7 @@ class ArtistsController < ApplicationController end def create - @artist = Artist.create(artist_params.merge(creator: CurrentUser.user)) + @artist = Artist.create(artist_params) respond_with(@artist) end diff --git a/app/controllers/notes_controller.rb b/app/controllers/notes_controller.rb index 3e7cf43c1..cbe959a42 100644 --- a/app/controllers/notes_controller.rb +++ b/app/controllers/notes_controller.rb @@ -7,7 +7,7 @@ class NotesController < ApplicationController def index @notes = Note.paginated_search(params) - @notes = @notes.includes(:creator, :post) if request.format.html? + @notes = @notes.includes(:post) if request.format.html? respond_with(@notes) end @@ -20,7 +20,7 @@ class NotesController < ApplicationController end def create - @note = Note.create(note_params(:create).merge(creator: CurrentUser.user)) + @note = Note.create(note_params(:create)) respond_with(@note) do |fmt| fmt.json do if @note.errors.any? diff --git a/app/controllers/pools_controller.rb b/app/controllers/pools_controller.rb index 410483ddd..282682ae8 100644 --- a/app/controllers/pools_controller.rb +++ b/app/controllers/pools_controller.rb @@ -18,7 +18,6 @@ class PoolsController < ApplicationController def index @pools = Pool.paginated_search(params, count_pages: true) - @pools = @pools.includes(:creator) if request.format.html? respond_with(@pools) end @@ -40,7 +39,7 @@ class PoolsController < ApplicationController end def create - @pool = Pool.create(pool_params.merge(creator: CurrentUser.user)) + @pool = Pool.create(pool_params) flash[:notice] = @pool.valid? ? "Pool created" : @pool.errors.full_messages.join("; ") respond_with(@pool) end diff --git a/app/models/artist.rb b/app/models/artist.rb index 650eb0637..3e53346b2 100644 --- a/app/models/artist.rb +++ b/app/models/artist.rb @@ -11,7 +11,6 @@ class Artist < ApplicationRecord after_save :clear_url_string_changed validate :validate_tag_category validates :name, tag_name: true, uniqueness: true - belongs_to :creator, class_name: "User" has_many :members, :class_name => "Artist", :foreign_key => "group_name", :primary_key => "name" has_many :urls, :dependent => :destroy, :class_name => "ArtistUrl", :autosave => true has_many :versions, -> {order("artist_versions.id ASC")}, :class_name => "ArtistVersion" @@ -386,7 +385,7 @@ class Artist < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :is_active, :is_banned, :creator, :name, :group_name, :other_names) + q = q.search_attributes(params, :is_active, :is_banned, :name, :group_name, :other_names) if params[:any_other_name_like] q = q.any_other_name_like(params[:any_other_name_like]) @@ -446,6 +445,6 @@ class Artist < ApplicationRecord end def self.available_includes - [:creator, :members, :urls, :wiki_page, :tag_alias, :tag] + [:members, :urls, :wiki_page, :tag_alias, :tag] end end diff --git a/app/models/note.rb b/app/models/note.rb index 428a070be..9675cc440 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -3,7 +3,6 @@ class Note < ApplicationRecord attr_accessor :html_id belongs_to :post - belongs_to :creator, class_name: "User" has_many :versions, -> {order("note_versions.id ASC")}, :class_name => "NoteVersion", :dependent => :destroy validates_presence_of :x, :y, :width, :height, :body validate :note_within_image @@ -19,7 +18,7 @@ class Note < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :creator, :post, :is_active, :x, :y, :width, :height, :body, :version) + q = q.search_attributes(params, :post, :is_active, :x, :y, :width, :height, :body, :version) q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index) q.apply_default_order(params) @@ -123,9 +122,8 @@ class Note < ApplicationRecord save! end - def copy_to(new_post, creator: CurrentUser.user) + def copy_to(new_post) new_note = dup - new_note.creator = creator new_note.post_id = new_post.id new_note.version = 0 @@ -154,6 +152,6 @@ class Note < ApplicationRecord end def self.available_includes - [:creator, :post] + [:post] end end diff --git a/app/models/pool.rb b/app/models/pool.rb index 679134772..5c84db978 100644 --- a/app/models/pool.rb +++ b/app/models/pool.rb @@ -3,7 +3,6 @@ class Pool < ApplicationRecord POOL_ORDER_LIMIT = 1000 array_attribute :post_ids, parse: /\d+/, cast: :to_i - belongs_to :creator, class_name: "User" validates_uniqueness_of :name, case_sensitive: false, if: :name_changed? validate :validate_name, if: :name_changed? @@ -53,7 +52,7 @@ class Pool < ApplicationRecord def search(params) q = super - q = q.search_attributes(params, :creator, :is_deleted, :name, :description, :post_ids) + q = q.search_attributes(params, :is_deleted, :name, :description, :post_ids) q = q.text_attribute_matches(:description, params[:description_matches]) if params[:post_tags_match] @@ -300,8 +299,4 @@ class Pool < ApplicationRecord errors[:base] << "You cannot removes posts from pools within the first week of sign up" end end - - def self.available_includes - [:creator] - end end diff --git a/app/views/artists/_search.html.erb b/app/views/artists/_search.html.erb index 174900da4..ccca9f484 100644 --- a/app/views/artists/_search.html.erb +++ b/app/views/artists/_search.html.erb @@ -1,7 +1,6 @@ <%= search_form_for(artists_path) do |f| %> <%= f.input :any_name_matches, label: "Name", hint: "Use * for wildcard", input_html: { value: params[:search][:any_name_matches], data: { autocomplete: "artist" }} %> <%= f.input :url_matches, label: "URL", as: "string", input_html: { value: params[:search][:url_matches] } %> - <%= f.input :creator_name, label: "Creator", input_html: { value: params[:search][:creator_name], data: { autocomplete: "user" } } %> <%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_active] %> <%= f.input :is_banned, label: "Banned?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_banned] %> <%= f.input :has_tag, label: "Has tag?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:has_tag] %> diff --git a/app/views/notes/index.html.erb b/app/views/notes/index.html.erb index 3558ebc77..6b29a33bb 100644 --- a/app/views/notes/index.html.erb +++ b/app/views/notes/index.html.erb @@ -19,8 +19,6 @@ <% end %> <% end %> <% t.column "Created" do |note| %> - <%= link_to_user note.creator %> - <%= link_to "ยป", notes_path(search: { creator_name: note.creator.name }) %>
<%= time_ago_in_words_tagged(note.created_at) %>
<% end %> <% end %> diff --git a/app/views/notes/search.html.erb b/app/views/notes/search.html.erb index aed18b82a..4aabd7e71 100644 --- a/app/views/notes/search.html.erb +++ b/app/views/notes/search.html.erb @@ -6,7 +6,6 @@ <%= f.hidden_field :group_by, value: "note" %> <%= f.input :body_matches, label: "Body" %> - <%= f.input :creator_name, label: "Author", input_html: { data: { autocomplete: "user" } } %> <%= f.input :post_tags_match, label: "Tags", input_html: { data: { autocomplete: "tag-query" } } %> <%= f.submit "Search" %> <% end %> diff --git a/app/views/pools/_search.html.erb b/app/views/pools/_search.html.erb index de424ed53..66adb5064 100644 --- a/app/views/pools/_search.html.erb +++ b/app/views/pools/_search.html.erb @@ -2,7 +2,6 @@ <%= f.input :name_matches, label: "Name", input_html: { value: params.dig(:search, :name_matches), "data-autocomplete": "pool" } %> <%= f.input :description_matches, label: "Description", input_html: { value: params.dig(:search, :description_matches) } %> <%= f.input :post_tags_match, label: "Post tags", input_html: { value: params.dig(:search, :post_tags_match), "data-autocomplete": "tag-query" } %> - <%= f.input :creator_name, label: "Creator", input_html: { value: params.dig(:search, :creator_name), "data-autocomplete": "user" } %> <%= f.input :category, collection: %w[series collection], include_blank: true, selected: params[:search][:category] %> <%= f.input :order, collection: [%w[Last\ updated updated_at], %w[Name name], %w[Recently\ created created_at], %w[Post\ count post_count]], include_blank: true, selected: params.dig(:search, :order) %> <%= f.submit "Search" %> diff --git a/db/migrate/20200217044719_drop_creator_from_artists_notes_pools.rb b/db/migrate/20200217044719_drop_creator_from_artists_notes_pools.rb new file mode 100644 index 000000000..78f9ecf8d --- /dev/null +++ b/db/migrate/20200217044719_drop_creator_from_artists_notes_pools.rb @@ -0,0 +1,10 @@ +class DropCreatorFromArtistsNotesPools < ActiveRecord::Migration[6.0] + def change + remove_index :pools, column: [:creator_id] + remove_index :notes, column: [:creator_id, :post_id] + + remove_column :artists, :creator_id, :integer, null: false + remove_column :notes, :creator_id, :integer, null: false + remove_column :pools, :creator_id, :integer, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index 17fa28460..9a3b78e96 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -594,7 +594,6 @@ ALTER SEQUENCE public.artist_versions_id_seq OWNED BY public.artist_versions.id; CREATE TABLE public.artists ( id integer NOT NULL, name character varying NOT NULL, - creator_id integer NOT NULL, is_active boolean DEFAULT true NOT NULL, is_banned boolean DEFAULT false NOT NULL, other_names text[] DEFAULT '{}'::text[] NOT NULL, @@ -2437,7 +2436,6 @@ ALTER SEQUENCE public.note_versions_id_seq OWNED BY public.note_versions.id; CREATE TABLE public.notes ( id integer NOT NULL, - creator_id integer NOT NULL, post_id integer NOT NULL, x integer NOT NULL, y integer NOT NULL, @@ -2509,7 +2507,6 @@ ALTER SEQUENCE public.pixiv_ugoira_frame_data_id_seq OWNED BY public.pixiv_ugoir CREATE TABLE public.pools ( id integer NOT NULL, name character varying, - creator_id integer NOT NULL, description text, is_active boolean DEFAULT true NOT NULL, post_ids integer[] DEFAULT '{}'::integer[] NOT NULL, @@ -6512,13 +6509,6 @@ CREATE INDEX index_note_versions_on_updater_ip_addr ON public.note_versions USIN CREATE INDEX index_notes_on_body_index ON public.notes USING gin (body_index); --- --- Name: index_notes_on_creator_id_and_post_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_notes_on_creator_id_and_post_id ON public.notes USING btree (creator_id, post_id); - - -- -- Name: index_notes_on_post_id; Type: INDEX; Schema: public; Owner: - -- @@ -6540,13 +6530,6 @@ CREATE UNIQUE INDEX index_pixiv_ugoira_frame_data_on_post_id ON public.pixiv_ugo CREATE INDEX index_pools_on_category ON public.pools USING btree (category); --- --- Name: index_pools_on_creator_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX index_pools_on_creator_id ON public.pools USING btree (creator_id); - - -- -- Name: index_pools_on_is_deleted; Type: INDEX; Schema: public; Owner: - -- @@ -7368,6 +7351,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20200118015014'), ('20200119184442'), ('20200119193110'), -('20200123184743'); +('20200123184743'), +('20200217044719'); diff --git a/test/factories/artist.rb b/test/factories/artist.rb index 5556f2e03..def197791 100644 --- a/test/factories/artist.rb +++ b/test/factories/artist.rb @@ -1,6 +1,5 @@ FactoryBot.define do factory(:artist) do - creator name { rand(1_000_000).to_s } is_active { true } end diff --git a/test/factories/note.rb b/test/factories/note.rb index 14c6a8093..6fbcd8a7e 100644 --- a/test/factories/note.rb +++ b/test/factories/note.rb @@ -1,6 +1,5 @@ FactoryBot.define do factory(:note) do - creator post x { 1 } y { 1 } diff --git a/test/factories/pool.rb b/test/factories/pool.rb index 63308fc91..3a77c93dc 100644 --- a/test/factories/pool.rb +++ b/test/factories/pool.rb @@ -1,6 +1,5 @@ FactoryBot.define do factory(:pool) do - creator name {"pool_" + rand(100..1000099).to_s} description {FFaker::Lorem.sentences.join(" ")} end diff --git a/test/unit/artist_test.rb b/test/unit/artist_test.rb index e03097afe..deca85f5e 100644 --- a/test/unit/artist_test.rb +++ b/test/unit/artist_test.rb @@ -524,7 +524,7 @@ class ArtistTest < ActiveSupport::TestCase context "#new_with_defaults" do should "fetch the defaults from the given source" do source = "https://i.pximg.net/img-original/img/2018/01/28/23/56/50/67014762_p0.jpg" - artist = Artist.new_with_defaults(source: source, creator: create(:user)) + artist = Artist.new_with_defaults(source: source) assert_equal("niceandcool", artist.name) assert_equal("nice_and_cool", artist.other_names_string)