From 50321533f7f271190c8ee54c89ea5e21d657f66d Mon Sep 17 00:00:00 2001 From: songtianlun Date: Mon, 27 Jan 2025 00:43:36 +0800 Subject: [PATCH] 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. --- app/admin/ahoy_events.rb | 2 -- app/admin/ahoy_management.rb | 2 +- app/admin/ahoy_visits.rb | 2 -- app/controllers/cities_controller.rb | 2 +- app/controllers/weather_arts_controller.rb | 4 ++-- app/models/ahoy/event.rb | 2 +- app/models/ahoy/visit.rb | 2 +- app/models/city.rb | 4 ++-- app/models/weather_art.rb | 4 ++-- app/workers/clean_ahoy_data_worker.rb | 6 +++--- db/migrate/20250126155239_create_ahoy_visits_and_events.rb | 4 ++-- 11 files changed, 15 insertions(+), 19 deletions(-) diff --git a/app/admin/ahoy_events.rb b/app/admin/ahoy_events.rb index f188a63..35e945b 100644 --- a/app/admin/ahoy_events.rb +++ b/app/admin/ahoy_events.rb @@ -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 diff --git a/app/admin/ahoy_management.rb b/app/admin/ahoy_management.rb index 0cb224e..8b6e9c7 100644 --- a/app/admin/ahoy_management.rb +++ b/app/admin/ahoy_management.rb @@ -31,4 +31,4 @@ ActiveAdmin.register_page "Ahoy Management" do CleanAhoyDataWorker.perform_async redirect_to admin_ahoy_management_path, notice: "清理任务已加入队列" end -end \ No newline at end of file +end diff --git a/app/admin/ahoy_visits.rb b/app/admin/ahoy_visits.rb index cad11d2..9bf914e 100644 --- a/app/admin/ahoy_visits.rb +++ b/app/admin/ahoy_visits.rb @@ -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 diff --git a/app/controllers/cities_controller.rb b/app/controllers/cities_controller.rb index fa3d6a1..1635d0a 100644 --- a/app/controllers/cities_controller.rb +++ b/app/controllers/cities_controller.rb @@ -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( diff --git a/app/controllers/weather_arts_controller.rb b/app/controllers/weather_arts_controller.rb index 58673fb..68b24cc 100644 --- a/app/controllers/weather_arts_controller.rb +++ b/app/controllers/weather_arts_controller.rb @@ -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( diff --git a/app/models/ahoy/event.rb b/app/models/ahoy/event.rb index 1509070..6c310d1 100644 --- a/app/models/ahoy/event.rb +++ b/app/models/ahoy/event.rb @@ -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 diff --git a/app/models/ahoy/visit.rb b/app/models/ahoy/visit.rb index 4e5aefc..18ceb4a 100644 --- a/app/models/ahoy/visit.rb +++ b/app/models/ahoy/visit.rb @@ -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 diff --git a/app/models/city.rb b/app/models/city.rb index 1b6ae13..6771ba4 100644 --- a/app/models/city.rb +++ b/app/models/city.rb @@ -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 diff --git a/app/models/weather_art.rb b/app/models/weather_art.rb index a297b0b..86da58e 100644 --- a/app/models/weather_art.rb +++ b/app/models/weather_art.rb @@ -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 diff --git a/app/workers/clean_ahoy_data_worker.rb b/app/workers/clean_ahoy_data_worker.rb index 5b5a8ce..b049e43 100644 --- a/app/workers/clean_ahoy_data_worker.rb +++ b/app/workers/clean_ahoy_data_worker.rb @@ -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 @@ -29,4 +29,4 @@ class CleanAhoyDataWorker Rails.logger.info "Remaining events: #{Ahoy::Event.count}" Rails.logger.info "Remaining visits: #{Ahoy::Visit.count}" end -end \ No newline at end of file +end diff --git a/db/migrate/20250126155239_create_ahoy_visits_and_events.rb b/db/migrate/20250126155239_create_ahoy_visits_and_events.rb index a9876e1..79be823 100644 --- a/db/migrate/20250126155239_create_ahoy_visits_and_events.rb +++ b/db/migrate/20250126155239_create_ahoy_visits_and_events.rb @@ -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