chore: clean up trailing whitespace and formatting

- Removed unnecessary leading and trailing blank lines in several
  ActiveAdmin register files.
- Reformatted string delimiters for consistency, changing single quotes
to double quotes in tracking events in the Cities and WeatherArts
controllers.
- Ensured proper spacing in array definitions across several
  models, including Ahoy::Event and Ahoy::Visit.

These changes improve code readability and maintain consistency
throughout the codebase by ensuring uniform use of quotes and
removing excess whitespace.
This commit is contained in:
songtianlun 2025-01-27 00:43:36 +08:00
parent dd6cd0451d
commit 50321533f7
11 changed files with 15 additions and 19 deletions

View File

@ -1,5 +1,4 @@
ActiveAdmin.register Ahoy::Event do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
@ -29,5 +28,4 @@ ActiveAdmin.register Ahoy::Event do
filter :name
filter :time
filter :properties
end

View File

@ -1,5 +1,4 @@
ActiveAdmin.register Ahoy::Visit do
# See permitted parameters documentation:
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
#
@ -33,5 +32,4 @@ ActiveAdmin.register Ahoy::Visit do
filter :started_at
filter :city
filter :country
end

View File

@ -27,7 +27,7 @@ class CitiesController < ApplicationController
ahoy.track "View City", {
city_id: @city.id,
name: @city.name,
event_type: 'city_view'
event_type: "city_view"
}
set_meta_tags(

View File

@ -6,12 +6,12 @@ class WeatherArtsController < ApplicationController
ahoy.track "View Weather Art", {
weather_art_id: @weather_art.id,
city_id: @weather_art.city_id,
event_type: 'weather_art_view'
event_type: "weather_art_view"
}
ahoy.track "View City", {
city_id: @city.id,
name: @city.name,
event_type: 'city_view'
event_type: "city_view"
}
set_meta_tags(

View File

@ -9,6 +9,6 @@ class Ahoy::Event < ApplicationRecord
serialize :properties, coder: JSON
def self.ransackable_attributes(auth_object = nil)
["id", "id_value", "name", "properties", "time", "user_id", "visit_id"]
[ "id", "id_value", "name", "properties", "time", "user_id", "visit_id" ]
end
end

View File

@ -5,6 +5,6 @@ class Ahoy::Visit < ApplicationRecord
belongs_to :user, optional: true
def self.ransackable_attributes(auth_object = nil)
["app_version", "browser", "city", "country", "device_type", "id", "ip", "landing_page", "latitude", "longitude", "os", "os_version", "platform", "referrer", "referring_domain", "region", "started_at", "user_agent", "user_id", "utm_campaign", "utm_content", "utm_medium", "utm_source", "utm_term", "visit_token", "visitor_token"]
[ "app_version", "browser", "city", "country", "device_type", "id", "ip", "landing_page", "latitude", "longitude", "os", "os_version", "platform", "referrer", "referring_domain", "region", "started_at", "user_agent", "user_id", "utm_campaign", "utm_content", "utm_medium", "utm_source", "utm_term", "visit_token", "visitor_token" ]
end
end

View File

@ -22,7 +22,7 @@ class City < ApplicationRecord
scope :by_popularity, -> {
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"
joins("LEFT JOIN ahoy_events ON json_extract(ahoy_events.properties, '$.city_id') = cities.id
AND json_extract(ahoy_events.properties, '$.event_type') = 'city_view'")
.group("cities.id")
@ -87,7 +87,7 @@ class City < ApplicationRecord
end
def view_count
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"
Ahoy::Event.where("json_extract(properties, '$.event_type') = 'city_view' AND json_extract(properties, '$.city_id') = ?", self.id).count
else
Ahoy::Event.where("properties->>'event_type' = 'city_view' AND (properties->>'city_id')::integer = ?", self.id).count

View File

@ -12,7 +12,7 @@ class WeatherArt < ApplicationRecord
validates :city_id, presence: true
scope :by_popularity, -> {
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"
joins("LEFT JOIN ahoy_events ON json_extract(ahoy_events.properties, '$.weather_art_id') = weather_arts.id
AND json_extract(ahoy_events.properties, '$.event_type') = 'weather_art_view'")
.group("weather_arts.id")
@ -44,7 +44,7 @@ class WeatherArt < ApplicationRecord
end
def view_count
if ActiveRecord::Base.connection.adapter_name.downcase == 'sqlite'
if ActiveRecord::Base.connection.adapter_name.downcase == "sqlite"
Ahoy::Event.where("json_extract(properties, '$.event_type') = 'weather_art_view' AND json_extract(properties, '$.weather_art_id') = ?", self.id).count
else
Ahoy::Event.where("properties->>'event_type' = 'weather_art_view' AND (properties->>'weather_art_id')::integer = ?", self.id).count

View File

@ -14,13 +14,13 @@ class CleanAhoyDataWorker
def cleanup_old_events
cutoff_date = 3.months.ago
deleted_events_count = Ahoy::Event.where('time < ?', cutoff_date).delete_all
deleted_events_count = Ahoy::Event.where("time < ?", cutoff_date).delete_all
Rails.logger.info "Deleted #{deleted_events_count} old Ahoy events"
end
def cleanup_old_visits
cutoff_date = 3.months.ago
deleted_visits_count = Ahoy::Visit.where('started_at < ?', cutoff_date).delete_all
deleted_visits_count = Ahoy::Visit.where("started_at < ?", cutoff_date).delete_all
Rails.logger.info "Deleted #{deleted_visits_count} old Ahoy visits"
end

View File

@ -45,7 +45,7 @@ class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[8.0]
end
add_index :ahoy_visits, :visit_token, unique: true
add_index :ahoy_visits, [:visitor_token, :started_at]
add_index :ahoy_visits, [ :visitor_token, :started_at ]
create_table :ahoy_events do |t|
t.references :visit
@ -56,6 +56,6 @@ class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[8.0]
t.datetime :time
end
add_index :ahoy_events, [:name, :time]
add_index :ahoy_events, [ :name, :time ]
end
end