also set _pending to 0 to prevent calling COMMIT too frequently

This commit is contained in:
Konstantin Käfer
2011-07-26 13:53:25 +02:00
parent 9e37bc4cc7
commit 44e9c7ebf7

View File

@@ -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();
});
};