You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by da...@apache.org on 2014/02/12 07:20:42 UTC

[48/52] [abbrv] fauxton commit: updated refs/heads/import-master to d11b90b

Add more caching locations


Project: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/commit/4b5735c7
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/tree/4b5735c7
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/diff/4b5735c7

Branch: refs/heads/import-master
Commit: 4b5735c7d4b456acbe457d3c7da675b8a0be0d20
Parents: f111540
Author: Garren Smith <ga...@gmail.com>
Authored: Wed Feb 5 19:23:12 2014 +0200
Committer: Garren Smith <ga...@gmail.com>
Committed: Wed Feb 5 19:23:12 2014 +0200

----------------------------------------------------------------------
 app/addons/databases/resources.js |  5 +++++
 app/addons/databases/routes.js    |  2 +-
 app/addons/databases/views.js     |  2 +-
 app/addons/documents/views.js     | 21 +++------------------
 app/core/base.js                  | 21 ++++++++++++++++++---
 app/core/couchdbSession.js        | 11 +++++++++--
 6 files changed, 37 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/addons/databases/resources.js
----------------------------------------------------------------------
diff --git a/app/addons/databases/resources.js b/app/addons/databases/resources.js
index 5fa931b..ea1aed2 100644
--- a/app/addons/databases/resources.js
+++ b/app/addons/databases/resources.js
@@ -171,6 +171,11 @@ function(app, FauxtonAPI, Documents) {
     documentation: function(){
       return "all_dbs";
     },
+
+    cache: {
+      expires: 60
+    },
+
     url: function(context) {
       if (context === "apiurl") { 
         return window.location.origin + "/_all_dbs";

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/addons/databases/routes.js
----------------------------------------------------------------------
diff --git a/app/addons/databases/routes.js b/app/addons/databases/routes.js
index c413018..131abf9 100644
--- a/app/addons/databases/routes.js
+++ b/app/addons/databases/routes.js
@@ -59,7 +59,7 @@ function(app, FauxtonAPI, Databases, Views) {
     },
 
     establish: function() {
-     return [this.databases.fetch()];
+     return [this.databases.fetchOnce()];
     }
   });
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/addons/databases/views.js
----------------------------------------------------------------------
diff --git a/app/addons/databases/views.js b/app/addons/databases/views.js
index afe2d1c..7f23d65 100644
--- a/app/addons/databases/views.js
+++ b/app/addons/databases/views.js
@@ -61,7 +61,7 @@ function(app, Components, FauxtonAPI, Databases) {
       var deferred = FauxtonAPI.Deferred();
 
       FauxtonAPI.when(currentDBs.map(function(database) {
-        return database.status.fetch();
+        return database.status.fetchOnce();
       })).always(function(resp) {
         //make this always so that even if a user is not allowed access to a database
         //they will still see a list of all databases

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/addons/documents/views.js
----------------------------------------------------------------------
diff --git a/app/addons/documents/views.js b/app/addons/documents/views.js
index 5476203..13cbacb 100644
--- a/app/addons/documents/views.js
+++ b/app/addons/documents/views.js
@@ -1804,30 +1804,15 @@ function(app, FauxtonAPI, Components, Documents, Databases, pouchdb, resizeColum
     template: "addons/documents/templates/changes",
 
     initialize: function () {
-      var that = this;
-      this.listenTo( this.model.changes, 'change', function () {
-        console.log('render on change'); 
-        that.render();
-      });
-      this.listenTo( this.model.changes, 'cachesync', function () {
-        console.log('render on cachesync'); 
-        that.render();
-      });
+      this.listenTo( this.model.changes, 'sync', this.render);
+      this.listenTo( this.model.changes, 'cachesync', this.render);
     },
 
     establish: function() {
-      return [ this.model.changes.fetchOnce({prefill: true,
-        success: function () {
-          console.log('hi ajax success');
-        },
-        prefillSuccess: function () {
-          console.log('hi prefill success');
-        }
-      })];
+      return [ this.model.changes.fetchOnce({prefill: true})];
     },
 
     serialize: function () {
-      console.log('ss');
       return {
         changes: this.model.changes.toJSON(),
         database: this.model

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/core/base.js
----------------------------------------------------------------------
diff --git a/app/core/base.js b/app/core/base.js
index 6fe3261..24b89cf 100644
--- a/app/core/base.js
+++ b/app/core/base.js
@@ -17,7 +17,6 @@ define([
 ],
 
 function(Backbone, LayoutManager, BackboneCache) {
-  console.log(BackboneCache);
   var FauxtonAPI = {
     //add default objects
     router: {
@@ -81,8 +80,24 @@ function(Backbone, LayoutManager, BackboneCache) {
   var caching = {
     fetchOnce: function (opts) {
       var options = _.defaults(opts || {}, this.cache, {cache: true});
-      console.log('opts', options);
-      return this.fetch(options);
+
+      if (opts && !opts.cache) {
+        delete options.cache;
+      }
+
+      if (!options.prefill) {
+        return this.fetch(options);
+      }
+
+      //With Prefill, the Caching with resolve with whatever is in the cache for that model/collection
+      //and at the sametime it will fetch from the server the latest. 
+      var promise = FauxtonAPI.Deferred(),
+          fetchPromise = this.fetch(options);
+
+      fetchPromise.progress(promise.resolveWith); // Fires when the cache hit happens
+      fetchPromise.then(promise.resolveWith); // Fires after the AJAX call
+
+      return promise;
     }
   };
 

http://git-wip-us.apache.org/repos/asf/couchdb-fauxton/blob/4b5735c7/app/core/couchdbSession.js
----------------------------------------------------------------------
diff --git a/app/core/couchdbSession.js b/app/core/couchdbSession.js
index 93bfd8a..b70ddf3 100644
--- a/app/core/couchdbSession.js
+++ b/app/core/couchdbSession.js
@@ -29,9 +29,16 @@ function (FauxtonAPI) {
 
       fetchUser: function (opt) {
         var that = this,
-        currentUser = this.user();
+            options = opt || {},
+        currentUser = this.user(),
+        fetch = this.fetchOnce;
 
-        return this.fetchOnce(opt).then(function () {
+        if (options.forceFetch) {
+          fetch = this.fetch;
+          Backbone.fetchCache.clearItem(_.result(this.url));
+        }
+
+        return this.fetch(opt).then(function () {
           var user = that.user();
 
           // Notify anyone listening on these events that either a user has changed