artist urls: stop using normalized_url.
Stop the last remaining uses of the `artist_urls.normalized_url` column. It's already no longer used by the artist finder. The only remaining uses were by API users. Those users should use the `url` column instead.
This commit is contained in:
@@ -218,7 +218,7 @@ module ArtistFinder
|
||||
def find_artists(url)
|
||||
return Artist.none if url.blank?
|
||||
|
||||
url = ArtistURL.normalize_normalized_url(url)
|
||||
url = ArtistURL.normalize_url(url)
|
||||
|
||||
# First try an exact match
|
||||
artists = Artist.active.joins(:urls).where(urls: { url: url })
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ArtistURL < ApplicationRecord
|
||||
self.ignored_columns = [:normalized_url]
|
||||
|
||||
normalize :url, :normalize_url
|
||||
|
||||
validates :url, presence: true, uniqueness: { scope: :artist_id }
|
||||
@@ -8,8 +10,6 @@ class ArtistURL < ApplicationRecord
|
||||
validate :validate_url_is_not_duplicate
|
||||
belongs_to :artist, :touch => true
|
||||
|
||||
scope :url_matches, ->(url) { url_attribute_matches(:url, url) }
|
||||
scope :normalized_url_matches, ->(url) { url_attribute_matches(:normalized_url, url) }
|
||||
scope :active, -> { where(is_active: true) }
|
||||
|
||||
def self.parse_prefix(url)
|
||||
@@ -19,23 +19,12 @@ class ArtistURL < ApplicationRecord
|
||||
[is_active, url]
|
||||
end
|
||||
|
||||
def self.normalize_normalized_url(url)
|
||||
return nil if url.nil?
|
||||
|
||||
url = Source::URL.parse(url)&.profile_url || url
|
||||
url = url.sub(%r{^https://}, "http://")
|
||||
url = url.gsub(%r{/+\Z}, "")
|
||||
url + "/"
|
||||
end
|
||||
|
||||
def self.search(params = {})
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :url, :normalized_url, :is_active, :artist)
|
||||
|
||||
q = search_attributes(params, :id, :created_at, :updated_at, :url, :is_active, :artist)
|
||||
q = q.url_matches(params[:url_matches])
|
||||
q = q.normalized_url_matches(params[:normalized_url_matches])
|
||||
|
||||
case params[:order]
|
||||
when /\A(id|artist_id|url|normalized_url|is_active|created_at|updated_at)(?:_(asc|desc))?\z/i
|
||||
when /\A(id|artist_id|url|is_active|created_at|updated_at)(?:_(asc|desc))?\z/i
|
||||
dir = $2 || :desc
|
||||
q = q.order($1 => dir).order(id: :desc)
|
||||
else
|
||||
@@ -45,16 +34,16 @@ class ArtistURL < ApplicationRecord
|
||||
q
|
||||
end
|
||||
|
||||
def self.url_attribute_matches(attr, url)
|
||||
def self.url_matches(url)
|
||||
if url.blank?
|
||||
all
|
||||
elsif url =~ %r{\A/(.*)/\z}
|
||||
where_regex(attr, $1)
|
||||
where_regex(:url, $1)
|
||||
elsif url.include?("*")
|
||||
where_ilike(attr, url)
|
||||
where_ilike(:url, url)
|
||||
else
|
||||
profile_url = Source::Extractor.find(url).profile_url || url
|
||||
where(attr => normalize_normalized_url(profile_url))
|
||||
profile_url = Source::Extractor.find(url).profile_url || normalize_url(url)
|
||||
where(url: profile_url)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -110,7 +99,6 @@ class ArtistURL < ApplicationRecord
|
||||
def url=(url)
|
||||
super(url)
|
||||
@parsed_url = Source::URL.parse(url)
|
||||
self.normalized_url = self.class.normalize_normalized_url(self.url)
|
||||
end
|
||||
|
||||
def parsed_url
|
||||
|
||||
@@ -5,7 +5,6 @@
|
||||
<%= fa.input :name, label: "Artist Name", input_html: { value: params.dig(:search, :artist, :name), "data-autocomplete": "artist" } %>
|
||||
<% end %>
|
||||
<%= f.input :url_matches, label: "URL", input_html: { value: params[:search][:url_matches] } %>
|
||||
<%= f.input :normalized_url_matches, label: "Normalized URL", input_html: { value: params[:search][:normalized_url_matches] } %>
|
||||
<%= f.input :is_active, label: "Active?", collection: [["Yes", true], ["No", false]], include_blank: true, selected: params[:search][:is_active] %>
|
||||
<%= f.input :order, collection: [["ID", "id"], ["Created", "created_at"], ["Updated", "updated_at"]], selected: params[:search][:order] %>
|
||||
<%= f.submit "Search" %>
|
||||
@@ -19,9 +18,6 @@
|
||||
<% t.column "URL" do |artist_url| %>
|
||||
<%= external_link_to(artist_url.url.to_s) %>
|
||||
<% end %>
|
||||
<% t.column "Normalized URL" do |artist_url| %>
|
||||
<%= external_link_to(artist_url.normalized_url) %>
|
||||
<% end %>
|
||||
<% t.column "Active?" do |artist_url| %>
|
||||
<%= artist_url.is_active.to_s %>
|
||||
<% end %>
|
||||
|
||||
Reference in New Issue
Block a user