Skip to content

Commit

Permalink
[rails] Fix after Postgres upgrade, attempt #4 (#658)
Browse files Browse the repository at this point in the history
* [react, rails] rollback some unnecessary changes in autofix-generate PR #655

* [rails] Revert all previous attemtpts

* [rails] fix reviews serialization after Postgres upgrade
  • Loading branch information
realkosty authored Jan 9, 2025
1 parent d27844a commit b5fb98d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 25 deletions.
2 changes: 0 additions & 2 deletions ruby-on-rails/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ gem 'nokogiri', '~>1.17.2'
# Use Rack CORS for handling Cross-Origin Resource Sharing (CORS), making cross-origin AJAX possible
gem 'rack-cors'
gem 'pg'
# Add serializer for proper JSON handling
gem 'active_model_serializers', '~> 0.10.13'

gem "stackprof"
gem "sentry-ruby"
Expand Down
12 changes: 7 additions & 5 deletions ruby-on-rails/app/controllers/api/v1/products_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ def index
span_products_db.finish

# n+1 to db if done this way
products.each do |prod_slow|
products = products.map do |prod|
span_products_slow_db = transaction.start_child(op: "custom.reviews_slow_db_call")
prod_slow["pg_sleep"] = ""
prod_slow["reviews"] = []
prod_slow["reviews"] = Reviews.select("id, productid, rating, customerid, description, created, Null as pg_sleep").where("productid="+prod_slow.id.to_s)
prod_attrs = prod.attributes
prod_attrs["pg_sleep"] = ""
prod_attrs["reviews"] = []
prod_attrs["reviews"] = Reviews.select("id, productid, rating, customerid, description, created, Null as pg_sleep").where("productid="+prod.id.to_s).as_json
span_products_slow_db.finish
prod_attrs
end

# fewer db calls this way -- done in products-join
Expand All @@ -40,7 +42,7 @@ def index
# end
# span_response.finish

render json: products, each_serializer: ProductSerializer, status: 200
render json: products, status: 200
end

# sent here if unexpected route was enterered
Expand Down
18 changes: 0 additions & 18 deletions ruby-on-rails/app/serializers/product_serializer.rb

This file was deleted.

0 comments on commit b5fb98d

Please sign in to comment.