Files
danbooru/app/models/wiki_page_version.rb
evazion 7e67d3dd9c views: replace .category-N css classes with .tag-type-N
* Replace the .category-N CSS classes on tags with .tag-type-N. Before
  we were inconsistent about whether tag colors were indicated with
  .category-N or .tag-type-N. Now it's always .tag-type-N.

* Fix various places to not use Tag.category_for. Tag.category_for does
  one Redis call per tag lookup, which leads to N Redis calls on many
  pages. This was inefficient because usually we either already had the
  tags from the database, or we could fetch them easily.
2020-02-16 04:35:37 -06:00

59 lines
1.3 KiB
Ruby

class WikiPageVersion < ApplicationRecord
array_attribute :other_names
belongs_to :wiki_page
belongs_to_updater
belongs_to :artist, optional: true
belongs_to :tag, primary_key: :name, foreign_key: :title, optional: true
module SearchMethods
def search(params)
q = super
q = q.search_attributes(params, :updater, :is_locked, :is_deleted, :wiki_page_id)
q = q.text_attribute_matches(:title, params[:title])
q = q.text_attribute_matches(:body, params[:body])
q.apply_default_order(params)
end
end
extend SearchMethods
def pretty_title
title.tr("_", " ")
end
def previous
@previous ||= begin
WikiPageVersion.where("wiki_page_id = ? and id < ?", wiki_page_id, id).order("id desc").limit(1).to_a
end
@previous.first
end
def self.status_fields
{
body: "Body",
other_names_changed: "OtherNames",
title: "Renamed",
was_deleted: "Deleted",
was_undeleted: "Undeleted",
}
end
def other_names_changed
((other_names - previous.other_names) | (previous.other_names - other_names)).length > 0
end
def was_deleted
is_deleted && !previous.is_deleted
end
def was_undeleted
!is_deleted && previous.is_deleted
end
def self.available_includes
[:updater, :wiki_page, :artist]
end
end