Class: Sitemap
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Sitemap
- Defined in:
- app/models/sitemap.rb
Constant Summary collapse
- RECENT_SITEMAP_NAME =
"recent"
- NEWS_SITEMAP_NAME =
"news"
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.regenerate_sitemaps ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'app/models/sitemap.rb', line 8 def regenerate_sitemaps names_used = [RECENT_SITEMAP_NAME, NEWS_SITEMAP_NAME] names_used.each { |name| touch(name) } count = Category.where(read_restricted: false).sum(:topic_count) max_page_size = SiteSetting.sitemap_page_size size, mod = count.divmod(max_page_size) size += 1 if mod > 0 size.times do |index| page_name = (index + 1).to_s touch(page_name) names_used << page_name end where.not(name: names_used).update_all(enabled: false) end |
.touch(name) ⇒ Object
27 28 29 30 31 |
# File 'app/models/sitemap.rb', line 27 def touch(name) find_or_initialize_by(name: name).tap do |sitemap| sitemap.update!(last_posted_at: sitemap.last_posted_topic || 3.days.ago, enabled: true) end end |
Instance Method Details
#last_posted_topic ⇒ Object
44 45 46 |
# File 'app/models/sitemap.rb', line 44 def last_posted_topic sitemap_topics.maximum(:updated_at) end |
#max_page_size ⇒ Object
48 49 50 |
# File 'app/models/sitemap.rb', line 48 def max_page_size SiteSetting.sitemap_page_size end |
#topics ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'app/models/sitemap.rb', line 34 def topics if name == RECENT_SITEMAP_NAME sitemap_topics.pluck(:id, :slug, :bumped_at, :updated_at, :posts_count) elsif name == NEWS_SITEMAP_NAME sitemap_topics.pluck(:id, :title, :slug, :created_at) else sitemap_topics.pluck(:id, :slug, :bumped_at, :updated_at) end end |