Skip to content

Commit

Permalink
Avoid unnecessary requests by checking most recent url before proceeding
Browse files Browse the repository at this point in the history
  • Loading branch information
twhitbeck authored and Jake Harding committed Jul 8, 2014
1 parent e2f6aea commit 917216b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/bloodhound/transport.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ var Transport = (function() {
var pendingRequestsCount = 0,
pendingRequests = {},
maxPendingRequests = 6,
requestCache = new LruCache(10);
requestCache = new LruCache(10),
lastUrl;

// constructor
// -----------
Expand Down Expand Up @@ -39,6 +40,10 @@ var Transport = (function() {
// ### private

_get: function(url, o, cb) {
if (url !== lastUrl) {
return;
}

var that = this, jqXhr;

// a request is already in progress, piggyback off of it
Expand Down Expand Up @@ -89,6 +94,8 @@ var Transport = (function() {
o = {};
}

lastUrl = url;

// in-memory cache hit
if (resp = requestCache.get(url)) {
// defer to stay consistent with behavior of ajax call
Expand Down

0 comments on commit 917216b

Please sign in to comment.