Commit 0060851a by Rocky Duan

add shared key authentication

parent 3b10ee3f
......@@ -35,6 +35,12 @@ APIPREFIX = CommentService::API_PREFIX
DEFAULT_PAGE = 1
DEFAULT_PER_PAGE = 20
if RACK_ENV.to_s != "test" # disable api_key auth in test environment
before do
error 401 unless params[:api_key] == CommentService.config[:api_key]
end
end
# these files must be required in order
require './api/search'
......
level_limit: 3
cache_enabled: false
api_key: "PUT_YOUR_API_KEY_HERE"
cache_timeout:
threads_search: 10
threads_query: 10
......@@ -74,7 +74,6 @@ helpers do
memcached_key = "threads_query_#{query_params.hash}"
cached_results = Sinatra::Application.cache.get(memcached_key)
if cached_results
puts "cache hit"
return {
collection: cached_results[:collection_ids].map{|id| CommentThread.find(id).to_hash(recursive: bool_recursive)},
num_pages: cached_results[:num_pages],
......@@ -83,8 +82,6 @@ helpers do
end
end
puts "cache miss"
sort_key_mapper = {
"date" => :created_at,
"activity" => :last_activity_at,
......
......@@ -94,10 +94,8 @@ class CommentThread < Content
memcached_key = "threads_search_#{params.merge(options).hash}"
results = Sinatra::Application.cache.get(memcached_key)
if results
puts "cache hit"
return results
end
puts "cache miss"
end
search = Tire::Search::Search.new 'comment_threads'
search.query {|query| query.text :_all, params["text"]} if params["text"]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment