Class: Api::V5::CompactRestaurantsController
- Inherits:
-
BaseController
- Object
- ActionController::API
- BaseController
- Api::V5::CompactRestaurantsController
- Defined in:
- app/controllers/api/v5/compact_restaurants_controller.rb
Overview
Featured Restaurants
Constant Summary
Constants inherited from BaseController
BaseController::CACHE_NAMESPACE, BaseController::INTERNAL_SERVER_ERROR_MESSAGE, BaseController::ResponseSchema
Instance Method Summary collapse
Methods inherited from BaseController
Methods included from LogrageCustomLogger
Methods included from ResponseCacheConcern
Instance Method Details
#index ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/api/v5/compact_restaurants_controller.rb', line 7 def index # DB level filtering branch_ids = params.require(:branch_ids).split(',').map(&:to_i) db_cache_key = CityHash.hash32([self.class.to_s, 'index', branch_ids.join(',')]) compact_restaurant_ids = Rails.cache.fetch(db_cache_key, expires_in: 5.minutes) do filter = CompactRestaurantsFilter.new filter.filter_restaurant_and_branch_ids(branch_ids: branch_ids, restaurant_ids: []) filter.page_number(1).per_page(100) [filter.collections.ids, filter.collections.cache_key] end response_cache_key = CityHash.hash32([self.class.to_s, db_cache_key, compact_restaurant_ids.last, MyLocaleManager.normalize_locale]) # cache JSON response my_response_cache(response_cache_key, :json, public: true) do compact_restaurants = CompactRestaurantsFilter.new compact_restaurants.filter_by_ids(compact_restaurant_ids.first) compact_restaurants.page_number(1).per_page(100) compact_restaurants.as_json(serialization_context, minor_version_param, {}).merge( success: true, message: nil ) end end |