Don't make pixiv http requests when displaying artist history
The reason the urls need to be normalized at all here is because legacy urls from Danbooru 1 don't have their unnormalized counterparts stored anywhere and thus can't be accurately compared with unnormalized urls from Danbooru 2.
This commit is contained in:
@@ -19,6 +19,21 @@ class ArtistUrl < ActiveRecord::Base
|
||||
end
|
||||
end
|
||||
|
||||
def self.legacy_normalize(url)
|
||||
if url.nil?
|
||||
nil
|
||||
else
|
||||
url = url.gsub(/^https:\/\//, "http://")
|
||||
url = url.gsub(/^http:\/\/blog\d+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/blog-imgs-\d+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/blog-imgs-\d+-\w+\.fc2/, "http://blog.fc2")
|
||||
url = url.gsub(/^http:\/\/img\d+\.pixiv\.net/, "http://img.pixiv.net")
|
||||
url = url.gsub(/^http:\/\/i\d+\.pixiv\.net\/img\d+/, "http://img.pixiv.net")
|
||||
url = url.gsub(/\/+\Z/, "")
|
||||
url + "/"
|
||||
end
|
||||
end
|
||||
|
||||
def self.normalize_for_search(url)
|
||||
if url =~ /\.\w+\Z/ && url =~ /\w\/\w/
|
||||
url = File.dirname(url)
|
||||
|
||||
@@ -69,8 +69,8 @@ class ArtistVersion < ActiveRecord::Base
|
||||
new_urls = url_array
|
||||
old_urls = version.present? ? version.url_array : []
|
||||
|
||||
new_urls = new_urls.map {|url| ArtistUrl.normalize(url)}
|
||||
old_urls = old_urls.map {|url| ArtistUrl.normalize(url)}
|
||||
new_urls = new_urls.map {|url| ArtistUrl.legacy_normalize(url)}
|
||||
old_urls = old_urls.map {|url| ArtistUrl.legacy_normalize(url)}
|
||||
|
||||
return {
|
||||
:added_urls => new_urls - old_urls,
|
||||
|
||||
Reference in New Issue
Block a user