Skip to content

Commit

Permalink
Fix: drop includes-count and active_model_serializers dependencies
Browse files Browse the repository at this point in the history
The includes-count gem has been abandonned and breaks ActiveRecord 5.0
badly (it freezes an internal collection), and it was easier to remove
active_model_serializers to replace includes-count than trying to fix
the one time usage of the serializer.
  • Loading branch information
ysbaddaden committed Nov 28, 2023
1 parent ef5385f commit 360332b
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 80 deletions.
2 changes: 0 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,13 @@ gem 'alto_guisso_rails', :git => "https://github.com/instedd/alto_guisso_rails",
# libraries
gem 'actionpack-action_caching'
gem 'actionpack-page_caching'
gem 'active_model_serializers' # TODO: consider removing (one serializer)
gem 'activerecord-import'
gem "breadcrumbs_on_rails"
gem 'carrierwave'
gem 'decent_exposure' # NOTE: pattern used in 12 out of 29 controllers (useful?)
gem 'gettext', '~> 3.1.2'
gem 'gettext_i18n_rails_js', git: "https://github.com/juanboca/gettext_i18n_rails_js.git", branch: 'master'
gem 'ice_cube'
# gem 'includes-count' # TODO: remove (only one use + breaking ActiveRecord with a frozen array)
gem "instedd-rails" #, '~> 0.0.24'
gem 'mini_magick'
gem 'msgpack', '~> 0.7.5'
Expand Down
9 changes: 0 additions & 9 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ GEM
erubis (~> 2.7.0)
rails-dom-testing (~> 2.0)
rails-html-sanitizer (~> 1.0, >= 1.0.3)
active_model_serializers (0.10.14)
actionpack (>= 4.1)
activemodel (>= 4.1)
case_transform (>= 0.2)
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
activejob (5.0.7.2)
activesupport (= 5.0.7.2)
globalid (>= 0.3.6)
Expand Down Expand Up @@ -118,8 +113,6 @@ GEM
marcel (~> 1.0.0)
mini_mime (>= 0.1.3)
ssrf_filter (~> 1.0)
case_transform (0.2)
activesupport
childprocess (0.9.0)
ffi (~> 1.0, >= 1.0.11)
coffee-rails (4.1.1)
Expand Down Expand Up @@ -236,7 +229,6 @@ GEM
activesupport (>= 4.2)
aes_key_wrap
bindata
jsonapi-renderer (0.2.2)
jwt (2.3.0)
knockoutjs-rails (3.5.1.1)
railties (>= 3.1)
Expand Down Expand Up @@ -471,7 +463,6 @@ PLATFORMS
DEPENDENCIES
actionpack-action_caching
actionpack-page_caching
active_model_serializers
activerecord-import
alto_guisso!
alto_guisso_rails!
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/api/collections_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Api::CollectionsController < ApiController
expose(:collection) { Collection.find(params[:collection_id] || params[:id]) }

def index
render json: current_user.collections.includes_count(:sites).load, each_serializer: Api::CollectionSerializer
collections = current_user.collections
render_json collections_json(collections, collections.count_sites)
end

def create
Expand Down
22 changes: 22 additions & 0 deletions app/helpers/api/json_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,28 @@ def collection_json(collection, results)
obj
end

def collections_json(collections, sites_counts)
collections.each do |collection|
{
anonymous_location_permission: collection.anonymous_location_permission,
anonymous_name_permission: collection.anonymous_name_permission,
created_at: collection.created_at,
description: collection.description,
icon: collection.icon,
id: collection.id,
lat: collection.lat,
lng: collection.lng,
max_lat: collection.max_lat,
max_lng: collection.max_lng,
min_lat: collection.min_lat,
min_lng: collection.min_lng,
name: collection.name,
updated_at:collection.updated_at,
count: sites_counts[collection.id].to_i,
}
end
end

def site_item_json(result)
source = result['_source']

Expand Down
4 changes: 4 additions & 0 deletions app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class Collection < ApplicationRecord
after_save :touch_lifespan
after_destroy :touch_lifespan

def self.count_sites
Site.where(collection_id: select(:id)).group(:collection_id).count
end

def max_value_of_property(es_code)
client = Elasticsearch::Client.new
results = client.search index: index_name, type: 'site', body: {
Expand Down
11 changes: 0 additions & 11 deletions app/serializers/api/collection_serializer.rb

This file was deleted.

36 changes: 0 additions & 36 deletions spec/serializers/api/collection_serializer_spec.rb

This file was deleted.

21 changes: 0 additions & 21 deletions spec/serializers/spec_helper.rb

This file was deleted.

0 comments on commit 360332b

Please sign in to comment.