added etags on prepare_for_display items and menuitems
This commit is contained in:
@@ -21,3 +21,4 @@ gem "json"
|
||||
gem 'puma'
|
||||
gem "sinatra-contrib"
|
||||
gem 'rerun'
|
||||
gem 'xxhash', '~> 0.3.0'
|
||||
|
||||
@@ -88,6 +88,7 @@ GEM
|
||||
hitimes
|
||||
tzinfo (1.2.2)
|
||||
thread_safe (~> 0.1)
|
||||
xxhash (0.3.0)
|
||||
|
||||
PLATFORMS
|
||||
java
|
||||
@@ -106,6 +107,7 @@ DEPENDENCIES
|
||||
sinatra
|
||||
sinatra-activerecord
|
||||
sinatra-contrib
|
||||
xxhash (~> 0.3.0)
|
||||
|
||||
BUNDLED WITH
|
||||
1.10.3
|
||||
|
||||
@@ -4,6 +4,7 @@ require './config'
|
||||
require 'json'
|
||||
require 'sinatra/cookies'
|
||||
require 'elasticsearch'
|
||||
require 'xxhash'
|
||||
|
||||
|
||||
Dir[File.dirname(__FILE__) + '/models/*.rb'].each {|file| require file }
|
||||
@@ -31,11 +32,14 @@ before do
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
helpers Sinatra::Cookies
|
||||
|
||||
def xxhash(text)
|
||||
seed = 31337
|
||||
XXhash.xxh32(text, seed)
|
||||
end
|
||||
|
||||
|
||||
|
||||
|
||||
Dir[File.dirname(__FILE__) + '/controllers/*.rb'].each {|file| require file }
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
def prepare_items_for_mass_display(items)
|
||||
items.to_json(
|
||||
items_json = items.to_json(
|
||||
:except => [:created_at, :current_input_price, :stock, :on_display],
|
||||
:include => [
|
||||
:unit ,
|
||||
@@ -7,6 +7,8 @@ def prepare_items_for_mass_display(items)
|
||||
:sub_category,
|
||||
:brand
|
||||
])
|
||||
etag xxhash(items_json)
|
||||
items_json
|
||||
end
|
||||
|
||||
def offset_and_limit_invalid?(offset, limit)
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
get '/menuitem' do
|
||||
# list all menu items
|
||||
MenuItem.eager_load(menu_sub_items: :menu_sub_sub_items)
|
||||
menu_items_json = MenuItem.eager_load(menu_sub_items: :menu_sub_sub_items)
|
||||
.order("menu_items.ordinal, menu_sub_items.ordinal, menu_sub_sub_items.ordinal")
|
||||
.to_json(:include => [:menu_sub_items => {:include => :menu_sub_sub_items}])
|
||||
etag xxhash(menu_items)
|
||||
menu_items_json
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user