From 44e9c7ebf70134c01a69f63cc3f3d13a32748a86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Ka=CC=88fer?= Date: Tue, 26 Jul 2011 13:53:25 +0200 Subject: [PATCH] also set _pending to 0 to prevent calling COMMIT too frequently --- lib/mbtiles.js | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/mbtiles.js b/lib/mbtiles.js index df32b61..66e5fd5 100644 --- a/lib/mbtiles.js +++ b/lib/mbtiles.js @@ -410,12 +410,7 @@ MBTiles.prototype.startWriting = function(callback) { var mbtiles = this; if (!this._isWritable) { this._isWritable = 1; - this._pending = 0; - this._tileCache = {}; - this._gridCache = {}; - this._keyCache = {}; - this._dataCache = {}; - this._mapCache = {}; + this._clearCaches(); this._db.run('PRAGMA synchronous=OFF', callback); } else { this._isWritable++; @@ -423,6 +418,15 @@ MBTiles.prototype.startWriting = function(callback) { } }; +MBTiles.prototype._clearCaches = function() { + this._pending = 0; + this._tileCache = {}; + this._gridCache = {}; + this._keyCache = {}; + this._dataCache = {}; + this._mapCache = {}; +}; + // (private) Commits the cached changes to the database. // // - @param {Function(err)} callback @@ -437,7 +441,6 @@ MBTiles.prototype._commit = function(callback) { for (var id in mbtiles._tileCache) { images.run(id, mbtiles._tileCache[id]); } - mbtiles._tileCache = {}; images.finalize(); } @@ -448,7 +451,6 @@ MBTiles.prototype._commit = function(callback) { for (var id in mbtiles._gridCache) { grids.run(id, mbtiles._gridCache[id]); } - mbtiles._gridCache = {}; grids.finalize(); } @@ -461,7 +463,6 @@ MBTiles.prototype._commit = function(callback) { keys.run(id, key); }); } - mbtiles._keyCache = {}; keys.finalize(); } @@ -472,7 +473,6 @@ MBTiles.prototype._commit = function(callback) { for (var key in mbtiles._dataCache) { keymap.run(key, JSON.stringify(mbtiles._dataCache[key])); } - mbtiles._dataCache = {}; keymap.finalize(); } @@ -503,12 +503,12 @@ MBTiles.prototype._commit = function(callback) { mapBoth.run(map.z, map.x, map.y, map.tile_id, map.grid_id); } } - mbtiles._mapCache = {}; mapBoth.finalize(); mapTile.finalize(); mapGrid.finalize(); mbtiles._db.run('COMMIT', callback); + mbtiles._clearCaches(); }); };