mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-14 00:37:10 +08:00
`.annotaterb.yml` has carried `classified_sort: true` since the project
switched from `annotate` to `annotaterb` (commit 0eab7daea4, July 2025),
but annotaterb's default behaviour is to compare the existing schema
block against what it would generate and skip the rewrite when the
column list matches — even when the *ordering* of those columns differs.
The result is that models which haven't had a schema change since the
config landed never get reordered, and `classified_sort` drift
accumulates indefinitely.
`--force` makes annotaterb always rewrite, so a single `bin/rake
annotate:clean` run brings every model into the canonical format and
keeps them there. Every schema block is now grouped primary-key →
regular columns → timestamps → foreign keys (alphabetical within each
group). Pure annotation comment change — no code modifications.
Also cleans up the rake task to avoid string interpolation for `system`
calls.
50 lines
1.3 KiB
Ruby
50 lines
1.3 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class WebCrawlerRequest < ActiveRecord::Base
|
|
include CachedCounting
|
|
|
|
cattr_accessor :max_record_age, :max_records_per_day
|
|
|
|
# only keep the top records based on request count
|
|
self.max_records_per_day = 200
|
|
|
|
# delete records older than this
|
|
self.max_record_age = 30.days
|
|
|
|
def self.increment!(user_agent)
|
|
perform_increment!(user_agent)
|
|
end
|
|
|
|
def self.write_cache!(user_agent, count, date)
|
|
where(id: request_id(date: date, user_agent: user_agent)).update_all(
|
|
["count = count + ?", count],
|
|
)
|
|
end
|
|
|
|
protected
|
|
|
|
def self.request_id(date:, user_agent:, retries: 0)
|
|
id = where(date: date, user_agent: user_agent).pick(:id)
|
|
id ||= create!({ date: date, user_agent: user_agent }.merge(count: 0)).id
|
|
rescue StandardError # primary key violation
|
|
if retries == 0
|
|
request_id(date: date, user_agent: user_agent, retries: 1)
|
|
else
|
|
raise
|
|
end
|
|
end
|
|
end
|
|
|
|
# == Schema Information
|
|
#
|
|
# Table name: web_crawler_requests
|
|
#
|
|
# id :bigint not null, primary key
|
|
# count :integer default(0), not null
|
|
# date :date not null
|
|
# user_agent :string not null
|
|
#
|
|
# Indexes
|
|
#
|
|
# index_web_crawler_requests_on_date_and_user_agent (date,user_agent) UNIQUE
|
|
#
|