Permalink
Browse files

don't compute the request object if we use the cache anyway

  • Loading branch information...
sigma committed Dec 6, 2011
1 parent 6de85e3 commit a783a2fabcc7e516127f1233f95dcd59ecd39268
Showing with 19 additions and 17 deletions.
  1. +19 −17 gh-api.el
View
@@ -167,30 +167,32 @@
(headers (when (eq fmt :form)
'(("Content-Type" . "application/x-www-form-urlencoded"))))
(cache (oref api :cache))
(req (gh-auth-modify-request
(oref api :auth)
(gh-api-request "request"
:method method
:url (concat (oref api :base)
(gh-api-expand-resource
api resource)
(if params
(gh-api-params-encode params)
""))
:headers headers
:data (or (and (eq fmt :json)
(gh-api-json-encode data))
(and (eq fmt :form)
(gh-api-form-encode data))
""))))
(key (and cache
(member method (oref cache safe-methods))
(list (format "%s@%s"
(oref (oref api :auth) :username)
resource)
method
transformer)))
(value (and key (pcache-get cache key))))
(value (and key (pcache-get cache key)))
(req
(and (not value) ;; we'll need the req only if value's not in cache
(gh-auth-modify-request
(oref api :auth)
(gh-api-request "request"
:method method
:url (concat (oref api :base)
(gh-api-expand-resource
api resource)
(if params
(gh-api-params-encode params)
""))
:headers headers
:data (or (and (eq fmt :json)
(gh-api-json-encode data))
(and (eq fmt :form)
(gh-api-form-encode data))
""))))))
(cond (value ;; got value from cache
(gh-api-response "cached" :data value))
(key ;; no value, but cache exists and method is safe

0 comments on commit a783a2f

Please sign in to comment.