Skip to content

Commit 360332b

Browse files
committed
Fix: drop includes-count and active_model_serializers dependencies
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.
1 parent ef5385f commit 360332b

8 files changed

Lines changed: 28 additions & 80 deletions

File tree

Gemfile

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,13 @@ gem 'alto_guisso_rails', :git => "https://github.com/instedd/alto_guisso_rails",
2828
# libraries
2929
gem 'actionpack-action_caching'
3030
gem 'actionpack-page_caching'
31-
gem 'active_model_serializers' # TODO: consider removing (one serializer)
3231
gem 'activerecord-import'
3332
gem "breadcrumbs_on_rails"
3433
gem 'carrierwave'
3534
gem 'decent_exposure' # NOTE: pattern used in 12 out of 29 controllers (useful?)
3635
gem 'gettext', '~> 3.1.2'
3736
gem 'gettext_i18n_rails_js', git: "https://github.com/juanboca/gettext_i18n_rails_js.git", branch: 'master'
3837
gem 'ice_cube'
39-
# gem 'includes-count' # TODO: remove (only one use + breaking ActiveRecord with a frozen array)
4038
gem "instedd-rails" #, '~> 0.0.24'
4139
gem 'mini_magick'
4240
gem 'msgpack', '~> 0.7.5'

Gemfile.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,6 @@ GEM
7171
erubis (~> 2.7.0)
7272
rails-dom-testing (~> 2.0)
7373
rails-html-sanitizer (~> 1.0, >= 1.0.3)
74-
active_model_serializers (0.10.14)
75-
actionpack (>= 4.1)
76-
activemodel (>= 4.1)
77-
case_transform (>= 0.2)
78-
jsonapi-renderer (>= 0.1.1.beta1, < 0.3)
7974
activejob (5.0.7.2)
8075
activesupport (= 5.0.7.2)
8176
globalid (>= 0.3.6)
@@ -118,8 +113,6 @@ GEM
118113
marcel (~> 1.0.0)
119114
mini_mime (>= 0.1.3)
120115
ssrf_filter (~> 1.0)
121-
case_transform (0.2)
122-
activesupport
123116
childprocess (0.9.0)
124117
ffi (~> 1.0, >= 1.0.11)
125118
coffee-rails (4.1.1)
@@ -236,7 +229,6 @@ GEM
236229
activesupport (>= 4.2)
237230
aes_key_wrap
238231
bindata
239-
jsonapi-renderer (0.2.2)
240232
jwt (2.3.0)
241233
knockoutjs-rails (3.5.1.1)
242234
railties (>= 3.1)
@@ -471,7 +463,6 @@ PLATFORMS
471463
DEPENDENCIES
472464
actionpack-action_caching
473465
actionpack-page_caching
474-
active_model_serializers
475466
activerecord-import
476467
alto_guisso!
477468
alto_guisso_rails!

app/controllers/api/collections_controller.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ class Api::CollectionsController < ApiController
99
expose(:collection) { Collection.find(params[:collection_id] || params[:id]) }
1010

1111
def index
12-
render json: current_user.collections.includes_count(:sites).load, each_serializer: Api::CollectionSerializer
12+
collections = current_user.collections
13+
render_json collections_json(collections, collections.count_sites)
1314
end
1415

1516
def create

app/helpers/api/json_helper.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,28 @@ def collection_json(collection, results)
1010
obj
1111
end
1212

13+
def collections_json(collections, sites_counts)
14+
collections.each do |collection|
15+
{
16+
anonymous_location_permission: collection.anonymous_location_permission,
17+
anonymous_name_permission: collection.anonymous_name_permission,
18+
created_at: collection.created_at,
19+
description: collection.description,
20+
icon: collection.icon,
21+
id: collection.id,
22+
lat: collection.lat,
23+
lng: collection.lng,
24+
max_lat: collection.max_lat,
25+
max_lng: collection.max_lng,
26+
min_lat: collection.min_lat,
27+
min_lng: collection.min_lng,
28+
name: collection.name,
29+
updated_at:collection.updated_at,
30+
count: sites_counts[collection.id].to_i,
31+
}
32+
end
33+
end
34+
1335
def site_item_json(result)
1436
source = result['_source']
1537

app/models/collection.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ class Collection < ApplicationRecord
3636
after_save :touch_lifespan
3737
after_destroy :touch_lifespan
3838

39+
def self.count_sites
40+
Site.where(collection_id: select(:id)).group(:collection_id).count
41+
end
42+
3943
def max_value_of_property(es_code)
4044
client = Elasticsearch::Client.new
4145
results = client.search index: index_name, type: 'site', body: {

app/serializers/api/collection_serializer.rb

Lines changed: 0 additions & 11 deletions
This file was deleted.

spec/serializers/api/collection_serializer_spec.rb

Lines changed: 0 additions & 36 deletions
This file was deleted.

spec/serializers/spec_helper.rb

Lines changed: 0 additions & 21 deletions
This file was deleted.

0 commit comments

Comments
 (0)