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:
parent
dd6cd0451d
commit
50321533f7
@ -1,5 +1,4 @@
|
|||||||
ActiveAdmin.register Ahoy::Event do
|
ActiveAdmin.register Ahoy::Event do
|
||||||
|
|
||||||
# See permitted parameters documentation:
|
# See permitted parameters documentation:
|
||||||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
|
# 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 :name
|
||||||
filter :time
|
filter :time
|
||||||
filter :properties
|
filter :properties
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -31,4 +31,4 @@ ActiveAdmin.register_page "Ahoy Management" do
|
|||||||
CleanAhoyDataWorker.perform_async
|
CleanAhoyDataWorker.perform_async
|
||||||
redirect_to admin_ahoy_management_path, notice: "清理任务已加入队列"
|
redirect_to admin_ahoy_management_path, notice: "清理任务已加入队列"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
ActiveAdmin.register Ahoy::Visit do
|
ActiveAdmin.register Ahoy::Visit do
|
||||||
|
|
||||||
# See permitted parameters documentation:
|
# See permitted parameters documentation:
|
||||||
# https://github.com/activeadmin/activeadmin/blob/master/docs/2-resource-customization.md#setting-up-strong-parameters
|
# 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 :started_at
|
||||||
filter :city
|
filter :city
|
||||||
filter :country
|
filter :country
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -27,7 +27,7 @@ class CitiesController < ApplicationController
|
|||||||
ahoy.track "View City", {
|
ahoy.track "View City", {
|
||||||
city_id: @city.id,
|
city_id: @city.id,
|
||||||
name: @city.name,
|
name: @city.name,
|
||||||
event_type: 'city_view'
|
event_type: "city_view"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_meta_tags(
|
set_meta_tags(
|
||||||
|
@ -6,12 +6,12 @@ class WeatherArtsController < ApplicationController
|
|||||||
ahoy.track "View Weather Art", {
|
ahoy.track "View Weather Art", {
|
||||||
weather_art_id: @weather_art.id,
|
weather_art_id: @weather_art.id,
|
||||||
city_id: @weather_art.city_id,
|
city_id: @weather_art.city_id,
|
||||||
event_type: 'weather_art_view'
|
event_type: "weather_art_view"
|
||||||
}
|
}
|
||||||
ahoy.track "View City", {
|
ahoy.track "View City", {
|
||||||
city_id: @city.id,
|
city_id: @city.id,
|
||||||
name: @city.name,
|
name: @city.name,
|
||||||
event_type: 'city_view'
|
event_type: "city_view"
|
||||||
}
|
}
|
||||||
|
|
||||||
set_meta_tags(
|
set_meta_tags(
|
||||||
|
@ -9,6 +9,6 @@ class Ahoy::Event < ApplicationRecord
|
|||||||
serialize :properties, coder: JSON
|
serialize :properties, coder: JSON
|
||||||
|
|
||||||
def self.ransackable_attributes(auth_object = nil)
|
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
|
||||||
end
|
end
|
||||||
|
@ -5,6 +5,6 @@ class Ahoy::Visit < ApplicationRecord
|
|||||||
belongs_to :user, optional: true
|
belongs_to :user, optional: true
|
||||||
|
|
||||||
def self.ransackable_attributes(auth_object = nil)
|
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
|
||||||
end
|
end
|
||||||
|
@ -22,7 +22,7 @@ class City < ApplicationRecord
|
|||||||
|
|
||||||
|
|
||||||
scope :by_popularity, -> {
|
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
|
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'")
|
AND json_extract(ahoy_events.properties, '$.event_type') = 'city_view'")
|
||||||
.group("cities.id")
|
.group("cities.id")
|
||||||
@ -87,7 +87,7 @@ class City < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def view_count
|
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
|
Ahoy::Event.where("json_extract(properties, '$.event_type') = 'city_view' AND json_extract(properties, '$.city_id') = ?", self.id).count
|
||||||
else
|
else
|
||||||
Ahoy::Event.where("properties->>'event_type' = 'city_view' AND (properties->>'city_id')::integer = ?", self.id).count
|
Ahoy::Event.where("properties->>'event_type' = 'city_view' AND (properties->>'city_id')::integer = ?", self.id).count
|
||||||
|
@ -12,7 +12,7 @@ class WeatherArt < ApplicationRecord
|
|||||||
validates :city_id, presence: true
|
validates :city_id, presence: true
|
||||||
|
|
||||||
scope :by_popularity, -> {
|
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
|
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'")
|
AND json_extract(ahoy_events.properties, '$.event_type') = 'weather_art_view'")
|
||||||
.group("weather_arts.id")
|
.group("weather_arts.id")
|
||||||
@ -44,7 +44,7 @@ class WeatherArt < ApplicationRecord
|
|||||||
end
|
end
|
||||||
|
|
||||||
def view_count
|
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
|
Ahoy::Event.where("json_extract(properties, '$.event_type') = 'weather_art_view' AND json_extract(properties, '$.weather_art_id') = ?", self.id).count
|
||||||
else
|
else
|
||||||
Ahoy::Event.where("properties->>'event_type' = 'weather_art_view' AND (properties->>'weather_art_id')::integer = ?", self.id).count
|
Ahoy::Event.where("properties->>'event_type' = 'weather_art_view' AND (properties->>'weather_art_id')::integer = ?", self.id).count
|
||||||
|
@ -14,13 +14,13 @@ class CleanAhoyDataWorker
|
|||||||
|
|
||||||
def cleanup_old_events
|
def cleanup_old_events
|
||||||
cutoff_date = 3.months.ago
|
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"
|
Rails.logger.info "Deleted #{deleted_events_count} old Ahoy events"
|
||||||
end
|
end
|
||||||
|
|
||||||
def cleanup_old_visits
|
def cleanup_old_visits
|
||||||
cutoff_date = 3.months.ago
|
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"
|
Rails.logger.info "Deleted #{deleted_visits_count} old Ahoy visits"
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -29,4 +29,4 @@ class CleanAhoyDataWorker
|
|||||||
Rails.logger.info "Remaining events: #{Ahoy::Event.count}"
|
Rails.logger.info "Remaining events: #{Ahoy::Event.count}"
|
||||||
Rails.logger.info "Remaining visits: #{Ahoy::Visit.count}"
|
Rails.logger.info "Remaining visits: #{Ahoy::Visit.count}"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -45,7 +45,7 @@ class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[8.0]
|
|||||||
end
|
end
|
||||||
|
|
||||||
add_index :ahoy_visits, :visit_token, unique: true
|
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|
|
create_table :ahoy_events do |t|
|
||||||
t.references :visit
|
t.references :visit
|
||||||
@ -56,6 +56,6 @@ class CreateAhoyVisitsAndEvents < ActiveRecord::Migration[8.0]
|
|||||||
t.datetime :time
|
t.datetime :time
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index :ahoy_events, [:name, :time]
|
add_index :ahoy_events, [ :name, :time ]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user