Skip to content

Commit ff6b892

Browse files
authored
Merge pull request #134 from dalthon/include-associations-on-api
Uses "includes" to avoid doing too much queries to database
2 parents 5fc8686 + ae6040e commit ff6b892

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

.travis.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ gemfile:
99
- gemfiles/rails_5.1.gemfile
1010
- gemfiles/rails_5.2.gemfile
1111
services:
12-
- redis-server
12+
- postgresql
13+
- redis-server
1314
env:
1415
- LIT_STORAGE=hash
1516
- LIT_STORAGE=redis
@@ -18,4 +19,3 @@ before_script:
1819
- psql -c 'create database lit_test;' -U postgres
1920
- RAILS_ENV=test bundle exec rake db:migrate
2021
script: "bundle exec rake test"
21-

app/controllers/lit/api/v1/localizations_controller.rb

+7-2
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,17 @@ def last_change
2222
private
2323

2424
def fetch_localizations
25+
scope = Localization.includes(
26+
:locale,
27+
:localization_key
28+
)
29+
2530
if params[:after].present?
2631
after_date = Time.parse("#{params[:after]} #{Time.zone.name}")
2732
.in_time_zone
28-
Localization.after(after_date).to_a
33+
scope.after(after_date).to_a
2934
else
30-
Localization.all
35+
scope.all
3136
end
3237
end
3338
end

0 commit comments

Comments
 (0)