Commit fcaa08e6 authored by Tristan Cavelier's avatar Tristan Cavelier

indexstorage.js updates unmodified db fixed

parent 37de729a
...@@ -197,6 +197,24 @@ ...@@ -197,6 +197,24 @@
*/ */
that._database = spec.database || []; that._database = spec.database || [];
/**
* True if it has been modified
*
* @property modified
* @type Boolean
* @default false
*/
that.modified = false;
/**
* Updates the modified date
*
* @method touch
*/
that.touch = function () {
that.modified = true;
};
/** /**
* Adds a metadata object in the database, replace if already exist * Adds a metadata object in the database, replace if already exist
* *
...@@ -232,10 +250,11 @@ ...@@ -232,10 +250,11 @@
that._database.push(needed_meta); that._database.push(needed_meta);
that._location[meta._id] = that._database.length - 1; that._location[meta._id] = that._database.length - 1;
} }
that.modified = true;
return true; return true;
} }
if (typeof that._location[meta._id] === "number") { if (typeof that._location[meta._id] === "number") {
that.remove(meta); return that.remove(meta);
} }
return false; return false;
}; };
...@@ -245,6 +264,7 @@ ...@@ -245,6 +264,7 @@
* *
* @method remove * @method remove
* @param {Object} meta The metadata to remove * @param {Object} meta The metadata to remove
* @return {Boolean} true if removed else false
*/ */
that.remove = function (meta) { that.remove = function (meta) {
if (typeof meta._id !== "string") { if (typeof meta._id !== "string") {
...@@ -252,11 +272,13 @@ ...@@ -252,11 +272,13 @@
} }
if (typeof that._location[meta._id] !== "number") { if (typeof that._location[meta._id] !== "number") {
// throw new ReferenceError("Not Found"); // throw new ReferenceError("Not Found");
return; return false;
} }
that._database[that._location[meta._id]] = null; that._database[that._location[meta._id]] = null;
that._free.push(that._location[meta._id]); that._free.push(that._location[meta._id]);
delete that._location[meta._id]; delete that._location[meta._id];
that.modified = true;
return true;
}; };
/** /**
...@@ -354,6 +376,8 @@ ...@@ -354,6 +376,8 @@
that._database.splice(i, 1); that._database.splice(i, 1);
} }
} }
that.modified = true;
return true;
}; };
/** /**
...@@ -454,11 +478,13 @@ ...@@ -454,11 +478,13 @@
IndexStorage.prototype.getIndexDatabase = function (command, index) { IndexStorage.prototype.getIndexDatabase = function (command, index) {
index = this._indices[index]; index = this._indices[index];
function makeNewIndex() { function makeNewIndex() {
return new JSONIndex({ var json_index = new JSONIndex({
"_id": index.id, "_id": index.id,
"_attachment": index.attachment || "body", "_attachment": index.attachment || "body",
"indexing": index.index "indexing": index.index
}); });
json_index.touch();
return json_index;
} }
return command.storage( return command.storage(
index.sub_storage || this._sub_storage index.sub_storage || this._sub_storage
...@@ -497,6 +523,9 @@ ...@@ -497,6 +523,9 @@
IndexStorage.prototype.storeIndexDatabase = function (command, database, IndexStorage.prototype.storeIndexDatabase = function (command, database,
index) { index) {
var that = this; var that = this;
if (!database.modified) {
return RSVP.resolve({"result": "success"});
}
index = this._indices[index]; index = this._indices[index];
function putAttachment() { function putAttachment() {
return command.storage( return command.storage(
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment