wiki pages: drop creator and updater fields.
Drop the creator_id and updater_id fields from wiki pages. These fields had several issues: * The creator_id field was inconsistent with the wiki_page_versions table. Apparently during the migration to Danbooru 2 in 2012-2013 the creator_id field got reset to whoever last updated the wiki at that point in time. * Saving a wiki would set the updater_id even when nothing actually changed. This also caused the updated_at timestamp to get bumped. Because of this, anything that saved a wiki, including things like creating aliases or implications, would bump the updater_id and updated_at even though the wiki didn't actually change. This meant these fields weren't consistent with the wiki_page_versions history. Changes: * Remove `creator_name` field from the /wiki_pages.json API. * Remove creator name search option from /wiki_pages/search.
This commit is contained in:
@@ -16,7 +16,7 @@ class WikiPagesController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@wiki_pages = WikiPage.includes(:creator).paginated_search(params)
|
@wiki_pages = WikiPage.paginated_search(params)
|
||||||
respond_with(@wiki_pages) do |format|
|
respond_with(@wiki_pages) do |format|
|
||||||
format.html do
|
format.html do
|
||||||
if params[:page].nil? || params[:page].to_i == 1
|
if params[:page].nil? || params[:page].to_i == 1
|
||||||
|
|||||||
@@ -15,14 +15,12 @@ class WikiPage < ApplicationRecord
|
|||||||
|
|
||||||
attr_accessor :skip_secondary_validations
|
attr_accessor :skip_secondary_validations
|
||||||
array_attribute :other_names
|
array_attribute :other_names
|
||||||
belongs_to_creator
|
|
||||||
belongs_to_updater
|
|
||||||
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
has_one :tag, :foreign_key => "name", :primary_key => "title"
|
||||||
has_one :artist, -> {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
has_one :artist, -> {where(:is_active => true)}, :foreign_key => "name", :primary_key => "title"
|
||||||
has_many :versions, -> {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
has_many :versions, -> {order("wiki_page_versions.id ASC")}, :class_name => "WikiPageVersion", :dependent => :destroy
|
||||||
has_many :dtext_links, as: :model, dependent: :destroy
|
has_many :dtext_links, as: :model, dependent: :destroy
|
||||||
|
|
||||||
api_attributes including: [:creator_name, :category_name]
|
api_attributes including: [:category_name]
|
||||||
|
|
||||||
module SearchMethods
|
module SearchMethods
|
||||||
def titled(title)
|
def titled(title)
|
||||||
@@ -63,7 +61,7 @@ class WikiPage < ApplicationRecord
|
|||||||
def search(params = {})
|
def search(params = {})
|
||||||
q = super
|
q = super
|
||||||
|
|
||||||
q = q.search_attributes(params, :creator, :updater, :is_locked, :is_deleted, :body)
|
q = q.search_attributes(params, :is_locked, :is_deleted, :body)
|
||||||
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
q = q.text_attribute_matches(:body, params[:body_matches], index_column: :body_index, ts_config: "danbooru")
|
||||||
|
|
||||||
if params[:title].present?
|
if params[:title].present?
|
||||||
@@ -102,10 +100,6 @@ class WikiPage < ApplicationRecord
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def creator_name
|
|
||||||
creator.name
|
|
||||||
end
|
|
||||||
|
|
||||||
extend SearchMethods
|
extend SearchMethods
|
||||||
|
|
||||||
def validate_not_locked
|
def validate_not_locked
|
||||||
|
|||||||
@@ -14,7 +14,7 @@
|
|||||||
<% @wiki_pages.each do |wiki_page| %>
|
<% @wiki_pages.each do |wiki_page| %>
|
||||||
<tr>
|
<tr>
|
||||||
<td class="category-<%= wiki_page.category_name %>"><%= link_to wiki_page.pretty_title, wiki_page_path(wiki_page, :noredirect => 1) %></td>
|
<td class="category-<%= wiki_page.category_name %>"><%= link_to wiki_page.pretty_title, wiki_page_path(wiki_page, :noredirect => 1) %></td>
|
||||||
<td><%= wiki_page.updated_at.strftime("%Y-%m-%d %H:%M") %> by <%= h link_to_user wiki_page.updater %></td>
|
<td><%= time_ago_in_words_tagged(wiki_page.updated_at) %></td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
</tbody>
|
</tbody>
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
<%= search_form_for(wiki_pages_path) do |f| %>
|
<%= search_form_for(wiki_pages_path) do |f| %>
|
||||||
<%= f.input :title, hint: "Use * for wildcard searches", input_html: { "data-autocomplete": "wiki-page" } %>
|
<%= f.input :title, hint: "Use * for wildcard searches", input_html: { "data-autocomplete": "wiki-page" } %>
|
||||||
<%= f.input :other_names_match, label: "Other names", hint: "Use * for wildcard searches" %>
|
<%= f.input :other_names_match, label: "Other names", hint: "Use * for wildcard searches" %>
|
||||||
<%= f.input :creator_name, input_html: { "data-autocomplete": "user" } %>
|
|
||||||
<%= f.input :body_matches, label: "Body" %>
|
<%= f.input :body_matches, label: "Body" %>
|
||||||
<%= f.input :other_names_present, as: :select %>
|
<%= f.input :other_names_present, as: :select %>
|
||||||
<%= f.input :hide_deleted, as: :select, include_blank: false %>
|
<%= f.input :hide_deleted, as: :select, include_blank: false %>
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
class DropCreatorAndUpdaterFromWikiPages < ActiveRecord::Migration[6.0]
|
||||||
|
def change
|
||||||
|
remove_column :wiki_pages, :creator_id, :integer
|
||||||
|
remove_column :wiki_pages, :updater_id, :integer
|
||||||
|
end
|
||||||
|
end
|
||||||
@@ -3206,14 +3206,12 @@ ALTER SEQUENCE public.wiki_page_versions_id_seq OWNED BY public.wiki_page_versio
|
|||||||
|
|
||||||
CREATE TABLE public.wiki_pages (
|
CREATE TABLE public.wiki_pages (
|
||||||
id integer NOT NULL,
|
id integer NOT NULL,
|
||||||
creator_id integer NOT NULL,
|
|
||||||
title character varying NOT NULL,
|
title character varying NOT NULL,
|
||||||
body text NOT NULL,
|
body text NOT NULL,
|
||||||
body_index tsvector NOT NULL,
|
body_index tsvector NOT NULL,
|
||||||
is_locked boolean DEFAULT false NOT NULL,
|
is_locked boolean DEFAULT false NOT NULL,
|
||||||
created_at timestamp without time zone,
|
created_at timestamp without time zone,
|
||||||
updated_at timestamp without time zone,
|
updated_at timestamp without time zone,
|
||||||
updater_id integer,
|
|
||||||
other_names text[] DEFAULT '{}'::text[] NOT NULL,
|
other_names text[] DEFAULT '{}'::text[] NOT NULL,
|
||||||
is_deleted boolean DEFAULT false NOT NULL
|
is_deleted boolean DEFAULT false NOT NULL
|
||||||
);
|
);
|
||||||
@@ -7408,6 +7406,7 @@ INSERT INTO "schema_migrations" (version) VALUES
|
|||||||
('20190919175836'),
|
('20190919175836'),
|
||||||
('20190923071044'),
|
('20190923071044'),
|
||||||
('20190926000912'),
|
('20190926000912'),
|
||||||
('20191023191749');
|
('20191023191749'),
|
||||||
|
('20191024194544');
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
FactoryBot.define do
|
FactoryBot.define do
|
||||||
factory(:wiki_page) do
|
factory(:wiki_page) do
|
||||||
creator :factory => :user
|
|
||||||
title {FFaker::Lorem.words.join(" ")}
|
title {FFaker::Lorem.words.join(" ")}
|
||||||
body {FFaker::Lorem.sentences.join(" ")}
|
body {FFaker::Lorem.sentences.join(" ")}
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user