Move setup step to #startWriting method.
This commit is contained in:
+17
-14
@@ -55,9 +55,6 @@ function MBTiles(uri, callback) {
|
|||||||
this._batchSize = +uri.query.batch;
|
this._batchSize = +uri.query.batch;
|
||||||
Step(function() {
|
Step(function() {
|
||||||
mbtiles._db = new sqlite3.Database(mbtiles.filename, this);
|
mbtiles._db = new sqlite3.Database(mbtiles.filename, this);
|
||||||
}, function(err) {
|
|
||||||
if (err) throw err;
|
|
||||||
mbtiles._setup(this);
|
|
||||||
}, function(err) {
|
}, function(err) {
|
||||||
if (err) throw err;
|
if (err) throw err;
|
||||||
fs.stat(mbtiles.filename, this);
|
fs.stat(mbtiles.filename, this);
|
||||||
@@ -389,18 +386,24 @@ MBTiles.prototype.startWriting = function(callback) {
|
|||||||
if (typeof callback !== 'function') throw new Error('Callback needed');
|
if (typeof callback !== 'function') throw new Error('Callback needed');
|
||||||
if (!this.open) return callback(new Error('MBTiles not yet loaded'));
|
if (!this.open) return callback(new Error('MBTiles not yet loaded'));
|
||||||
|
|
||||||
// Sets the synchronous flag to OFF for (much) faster inserts.
|
|
||||||
// See http://www.sqlite3.org/pragma.html#pragma_synchronous
|
|
||||||
|
|
||||||
var mbtiles = this;
|
var mbtiles = this;
|
||||||
if (!this._isWritable) {
|
Step(function() {
|
||||||
this._isWritable = 1;
|
mbtiles._setup(this);
|
||||||
this._clearCaches();
|
}, function(err) {
|
||||||
this._db.run('PRAGMA synchronous=OFF', callback);
|
if (err) throw err;
|
||||||
} else {
|
// Sets the synchronous flag to OFF for (much) faster inserts.
|
||||||
this._isWritable++;
|
// See http://www.sqlite3.org/pragma.html#pragma_synchronous
|
||||||
return callback(null);
|
if (!mbtiles._isWritable) {
|
||||||
}
|
mbtiles._isWritable = 1;
|
||||||
|
mbtiles._clearCaches();
|
||||||
|
mbtiles._db.run('PRAGMA synchronous=OFF', this);
|
||||||
|
} else {
|
||||||
|
mbtiles._isWritable++;
|
||||||
|
this();
|
||||||
|
}
|
||||||
|
}, function(err) {
|
||||||
|
return callback(err);
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
MBTiles.prototype._clearCaches = function() {
|
MBTiles.prototype._clearCaches = function() {
|
||||||
|
|||||||
+2
-2
@@ -61,7 +61,7 @@ exports['get/put metadata from empty file'] = function(beforeExit) {
|
|||||||
|
|
||||||
assert.deepEqual({
|
assert.deepEqual({
|
||||||
basename: "empty.mbtiles",
|
basename: "empty.mbtiles",
|
||||||
filesize: 16384,
|
filesize: 0,
|
||||||
id: "empty",
|
id: "empty",
|
||||||
scheme: "tms"
|
scheme: "tms"
|
||||||
}, data);
|
}, data);
|
||||||
@@ -89,7 +89,7 @@ exports['get/put metadata from empty file'] = function(beforeExit) {
|
|||||||
|
|
||||||
assert.deepEqual({
|
assert.deepEqual({
|
||||||
basename: "empty.mbtiles",
|
basename: "empty.mbtiles",
|
||||||
filesize: 16384,
|
filesize: 0,
|
||||||
id: "empty",
|
id: "empty",
|
||||||
scheme: "tms",
|
scheme: "tms",
|
||||||
version: "1.0.0"
|
version: "1.0.0"
|
||||||
|
|||||||
Reference in New Issue
Block a user