docbrown/config/sitemap.rb
Ben Halpern 152f4a52ea
Remove unnecessary queries (#1717)
* filter unnecessary queries

* Adjust article query in a couple places

* Replace tagged_with in main tag query

* Cache_tagged_with additional queries

* Modify test

* Modify cached_tagged_with to account for single tags

* Add cached_tagged_with in a few more places
2019-02-02 21:40:34 -04:00

31 lines
1.2 KiB
Ruby

if Rails.env.production?
SitemapGenerator::Sitemap.adapter = SitemapGenerator::S3Adapter.new(
fog_provider: "AWS",
aws_access_key_id: ApplicationConfig["AWS_ID"],
aws_secret_access_key: ApplicationConfig["AWS_SECRET"],
fog_directory: ApplicationConfig["AWS_BUCKET_NAME"],
fog_region: "us-east-1",
)
SitemapGenerator::Sitemap.public_path = "tmp/"
SitemapGenerator::Sitemap.sitemaps_host = "https://thepracticaldev.s3.amazonaws.com/"
SitemapGenerator::Sitemap.sitemaps_path = "sitemaps/"
end
SitemapGenerator::Sitemap.default_host = "#{ApplicationConfig['APP_PROTOCOL']}#{ApplicationConfig['APP_DOMAIN']}"
SitemapGenerator::Sitemap.create do
Article.where(published: true).
where("score > ? OR featured = ?", 12, true).
where(published: true).limit(38000).find_each do |article|
add article.path, lastmod: article.last_comment_at, changefreq: "daily"
end
User.order("comments_count DESC").where("updated_at > ?", 5.days.ago).limit(8000).find_each do |user|
add "/#{user.username}", changefreq: "daily"
end
Tag.order("hotness_score DESC").limit(250).find_each do |tag|
add "/t/#{tag.name}", changefreq: "daily"
end
end