From e8aa6fc388cffbcf02109b67c172c0a469c087cb Mon Sep 17 00:00:00 2001 From: songtianlun Date: Tue, 8 Apr 2025 14:18:48 +0800 Subject: [PATCH] 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. --- app/workers/submit_to_indexnow_worker.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/workers/submit_to_indexnow_worker.rb b/app/workers/submit_to_indexnow_worker.rb index 5058866..d93dd67 100644 --- a/app/workers/submit_to_indexnow_worker.rb +++ b/app/workers/submit_to_indexnow_worker.rb @@ -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|