Created
October 28, 2013 20:49
-
-
Save pm-dev/7204416 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/rails/app/controllers/api/v0/mobile_search_controller.rb b/rails/app/controllers/api/v0/mobile_search_controller.rb | |
index 6006be0..ab824ef 100644 | |
--- a/rails/app/controllers/api/v0/mobile_search_controller.rb | |
+++ b/rails/app/controllers/api/v0/mobile_search_controller.rb | |
@@ -16,29 +16,16 @@ module Api | |
render :json => MultiJson.dump(response_json) | |
end | |
+ protected | |
def self.get_categories(cached) | |
key = { c: controller_name, q: 'categories'} | |
- if cached | |
- categories = Rails.cache.fetch key, expires_in: CATEGORY_CACHE_TTL do | |
- MobileSearchController.uncached_categories | |
- end | |
- else | |
- categories = MobileSearchController.uncached_categories | |
- Rails.cache.write key, categories, expires_in: CATEGORY_CACHE_TTL | |
+ response_json = Rails.cache.fetch key, expires_in: CATEGORY_CACHE_TTL do | |
+ result = Okl::King::MobileSearchCategory.where(parent_mobile_search_category_id: nil) | |
+ result.collect { |l1_category| MobileSearchController.populate_category(l1_category)} | |
end | |
end | |
- | |
- protected | |
- | |
- | |
- def self.uncached_categories | |
- result = Okl::King::MobileSearchCategory.where(parent_mobile_search_category_id: nil) | |
- result.collect { |l1_category| MobileSearchController.populate_category(l1_category)} | |
- end | |
- | |
- | |
def self.populate_category(category) | |
category_hash = { name: category.name, category_id: category.id, hidden: category.hidden, search_query: category.query_string } | |
if category.mobile_search_categories.blank? | |
@@ -86,7 +73,6 @@ module Api | |
str | |
end | |
- | |
def self.products(search_response) | |
search_json = JSON.parse search_response | |
hits_array = search_json["hits"]["hits"] | |
diff --git a/rails/config/schedule.rb b/rails/config/schedule.rb | |
index 346114e..5ac2cf9 100644 | |
--- a/rails/config/schedule.rb | |
+++ b/rails/config/schedule.rb | |
@@ -21,5 +21,5 @@ | |
# Learn more: http://github.com/javan/whenever | |
every 1.day, :at => '8:05 am' do | |
- Api::V0::MobileSearchController.get_categories(NO) | |
+ | |
end | |
diff --git a/rails/spec/controllers/api/v0/mobile_search_controller_spec.rb b/rails/spec/controllers/api/v0/mobile_search_controller_spec.rb | |
index aaf0c4a..b6f0585 100644 | |
--- a/rails/spec/controllers/api/v0/mobile_search_controller_spec.rb | |
+++ b/rails/spec/controllers/api/v0/mobile_search_controller_spec.rb | |
@@ -2,6 +2,7 @@ require 'spec_helper' | |
module Api | |
module V0 | |
+ #include Okl::King | |
describe MobileSearchController do | |
let(:l1_category) { create(:mobile_search_category) } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment