Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add http caching to gist search requests

  • Loading branch information...
commit 868f86113d65349b771c0476f83241de5c38202e 1 parent 2cbb120
@rwdaigle authored
Showing with 13 additions and 7 deletions.
  1. +13 −7 app/controllers/gists_controller.rb
View
20 app/controllers/gists_controller.rb
@@ -6,15 +6,17 @@ class GistsController < ApplicationController
JUMP_CHAR = '!'
- def index
- @gists = current_user.gists.order("gh_created_at DESC").includes(:files)
- end
+ # def index
+ # @gists = current_user.gists.order("gh_created_at DESC").includes(:files)
+ # end
def search
- @results = Gist.search(current_user, normalized_query)
- if(feeling_lucky_directive? && lucky_result = @results.first)
- redirect_to lucky_result.url
- log({ns: self.class, fn: __method__, measure: true, at: 'auto-jump', query: params[:q]}, {:'redirect-to' => lucky_result.url}, current_user)
+ if stale?(etag: search_etag, last_modified: current_user.last_gh_fetch)
+ @results = Gist.search(current_user, normalized_query)
+ if(feeling_lucky_directive? && lucky_result = @results.first)
+ redirect_to lucky_result.url
+ log({ns: self.class, fn: __method__, measure: true, at: 'auto-jump', query: params[:q]}, {:'redirect-to' => lucky_result.url}, current_user)
+ end
end
end
@@ -34,4 +36,8 @@ def feeling_lucky_directive?
params[:q] && JUMP_CHAR == params[:q].last
end
+ def search_etag
+ "#{CACHE_VERSION}-#{current_user.id}-#{params[:q]}"
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.