Optimize Sources::Strategies.find()
Use lazy.map instead of map, so that we do not run every single strategy's match method for every source
This commit is contained in:
@@ -3,24 +3,24 @@ module Sources
|
|||||||
def self.all
|
def self.all
|
||||||
[
|
[
|
||||||
Strategies::Pixiv,
|
Strategies::Pixiv,
|
||||||
Strategies::Fanbox,
|
|
||||||
Strategies::NicoSeiga,
|
|
||||||
Strategies::Twitter,
|
Strategies::Twitter,
|
||||||
|
Strategies::Tumblr,
|
||||||
|
Strategies::NicoSeiga,
|
||||||
Strategies::Stash, # must come before DeviantArt
|
Strategies::Stash, # must come before DeviantArt
|
||||||
Strategies::DeviantArt,
|
Strategies::DeviantArt,
|
||||||
Strategies::Tumblr,
|
|
||||||
Strategies::ArtStation,
|
|
||||||
Strategies::Nijie,
|
|
||||||
Strategies::Mastodon,
|
|
||||||
Strategies::Moebooru,
|
Strategies::Moebooru,
|
||||||
|
Strategies::Nijie,
|
||||||
|
Strategies::ArtStation,
|
||||||
Strategies::HentaiFoundry,
|
Strategies::HentaiFoundry,
|
||||||
|
Strategies::Fanbox,
|
||||||
|
Strategies::Mastodon,
|
||||||
Strategies::Weibo,
|
Strategies::Weibo,
|
||||||
Strategies::Newgrounds
|
Strategies::Newgrounds
|
||||||
]
|
]
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.find(url, referer = nil, default: Strategies::Null)
|
def self.find(url, referer = nil, default: Strategies::Null)
|
||||||
strategy = all.map { |strategy| strategy.new(url, referer) }.detect(&:match?)
|
strategy = all.lazy.map { |s| s.new(url, referer) }.detect(&:match?)
|
||||||
strategy || default&.new(url, referer)
|
strategy || default&.new(url, referer)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user