fix: update URL collection to filter by recently updated
- Modify the collect_urls method to accept a recently_updated parameter for filtering. - Update the queries for City and WeatherArt models to only include records updated after the specified time. - This change improves the efficiency of URL collection by ensuring that outdated entries are not submitted, thus aligning with IndexNow requirements.
This commit is contained in:
parent
5852d8724e
commit
e8aa6fc388
@ -28,7 +28,7 @@ class SubmitToIndexnowWorker
|
||||
Rails.application.routes.default_url_options[:host] = @host
|
||||
|
||||
# 收集所有需要提交的 URLs
|
||||
urls = collect_urls
|
||||
urls = collect_urls(recently_updated)
|
||||
|
||||
# 分批提交 URLs (每批最多 10000 个 URLs,符合 IndexNow 限制)
|
||||
urls.each_slice(100) do |url_batch|
|
||||
@ -50,7 +50,7 @@ class SubmitToIndexnowWorker
|
||||
|
||||
private
|
||||
|
||||
def collect_urls
|
||||
def collect_urls(recently_updated)
|
||||
urls = []
|
||||
available_locales = I18n.available_locales
|
||||
|
||||
@ -73,7 +73,8 @@ class SubmitToIndexnowWorker
|
||||
end
|
||||
|
||||
# 城市详情页
|
||||
City.find_each do |city|
|
||||
City.where("updated_at > ?", recently_updated).find_each do |city|
|
||||
# City.find_each do |city|
|
||||
urls << "#{@host}/cities/#{city.id}"
|
||||
available_locales.each do |locale|
|
||||
urls << "#{@host}/#{locale}/cities/#{city.id}"
|
||||
@ -81,7 +82,8 @@ class SubmitToIndexnowWorker
|
||||
end
|
||||
|
||||
# 天气艺术作品页
|
||||
WeatherArt.includes(:city).find_each do |art|
|
||||
WeatherArt.includes(:city).where("updated_at > ?", recently_updated).find_each do |art|
|
||||
# WeatherArt.includes(:city).find_each do |art|
|
||||
if art.image.attached?
|
||||
urls << "#{@host}/cities/#{art.city.id}/weather_arts/#{art.id}"
|
||||
available_locales.each do |locale|
|
||||
|
Loading…
Reference in New Issue
Block a user