Commit 0b0e0149 authored by lucas.parsy's avatar lucas.parsy

removed useless table in websqlstorage

added indexes to increase queries speed.
parent fbdd12ad
...@@ -55,21 +55,17 @@ ...@@ -55,21 +55,17 @@
"CREATE TABLE IF NOT EXISTS document" + "CREATE TABLE IF NOT EXISTS document" +
"(id VARCHAR PRIMARY KEY NOT NULL, data TEXT)", "(id VARCHAR PRIMARY KEY NOT NULL, data TEXT)",
"CREATE TABLE IF NOT EXISTS attachment" + "CREATE TABLE IF NOT EXISTS attachment" +
"(id VARCHAR, attachment VARCHAR, " +
"CONSTRAINT uniq UNIQUE (id, attachment))",
"CREATE TABLE IF NOT EXISTS blob" +
"(id VARCHAR, attachment VARCHAR, part INT, blob TEXT)", "(id VARCHAR, attachment VARCHAR, part INT, blob TEXT)",
"CREATE TRIGGER IF NOT EXISTS remove " +
"BEFORE DELETE ON document FOR EACH ROW BEGIN DELETE " +
"FROM attachment WHERE id = OLD.id;END;",
"CREATE TRIGGER IF NOT EXISTS removeAttachment " + "CREATE TRIGGER IF NOT EXISTS removeAttachment " +
"BEFORE DELETE ON attachment FOR EACH ROW " + "BEFORE DELETE ON document FOR EACH ROW " +
"BEGIN DELETE from blob WHERE id = OLD.id " + "BEGIN DELETE from attachment WHERE id = OLD.id;END;",
"AND attachment = OLD.attachment;END;" "CREATE INDEX IF NOT EXISTS index_document ON document (id);",
"CREATE INDEX IF NOT EXISTS index_attachment " +
"ON attachment (id, attachment);"
]; ];
return new RSVP.Queue() return new RSVP.Queue()
.push(function () { .push(function () {
return queueSql(db, query_list, [[], [], [], [], []]); return queueSql(db, query_list, []);
}); });
} }
...@@ -159,7 +155,7 @@ ...@@ -159,7 +155,7 @@
.push(function () { .push(function () {
return queueSql(db, [ return queueSql(db, [
"SELECT id FROM document WHERE id = ?", "SELECT id FROM document WHERE id = ?",
"SELECT attachment FROM attachment WHERE id = ?" "SELECT DISTINCT attachment FROM attachment WHERE id = ?"
], [[id], [id]]); ], [[id], [id]]);
}) })
.push(function (result_list) { .push(function (result_list) {
...@@ -183,7 +179,7 @@ ...@@ -183,7 +179,7 @@
return jIO.util.readBlobAsDataURL(blob); return jIO.util.readBlobAsDataURL(blob);
}) })
.push(function (strBlob) { .push(function (strBlob) {
argument_list[index + 3].push(strBlob.currentTarget.result); argument_list[index + 2].push(strBlob.currentTarget.result);
return; return;
}); });
} }
...@@ -211,18 +207,16 @@ ...@@ -211,18 +207,16 @@
if (result[0].rows.length === 0) { if (result[0].rows.length === 0) {
throw new jIO.util.jIOError("Cannot access subdocument", 404); throw new jIO.util.jIOError("Cannot access subdocument", 404);
} }
query_list.push("INSERT OR REPLACE INTO attachment(id, attachment)" + query_list.push("DELETE FROM attachment WHERE id = ? " +
" VALUES(?, ?)"); "AND attachment = ?");
argument_list.push([id, name]); argument_list.push([id, name]);
query_list.push("DELETE FROM blob WHERE id = ? AND attachment = ?"); query_list.push("INSERT INTO attachment(id, attachment, part, blob)" +
argument_list.push([id, name]);
query_list.push("INSERT INTO blob(id, attachment, part, blob)" +
"VALUES(?, ?, ?, ?)"); "VALUES(?, ?, ?, ?)");
argument_list.push([id, name, -1, argument_list.push([id, name, -1,
blob.type || "application/octet-stream"]); blob.type || "application/octet-stream"]);
for (i = 0, index = 0; i < blob_size; i += part_size, index += 1) { for (i = 0, index = 0; i < blob_size; i += part_size, index += 1) {
query_list.push("INSERT INTO blob(id, attachment, part, blob)" + query_list.push("INSERT INTO attachment(id, attachment, part, blob)" +
"VALUES(?, ?, ?, ?)"); "VALUES(?, ?, ?, ?)");
argument_list.push([id, name, index]); argument_list.push([id, name, index]);
sendBlobPart(blob.slice(i, i + part_size), argument_list, index, sendBlobPart(blob.slice(i, i + part_size), argument_list, index,
...@@ -269,7 +263,7 @@ ...@@ -269,7 +263,7 @@
return that._init_db_promise; return that._init_db_promise;
}) })
.push(function () { .push(function () {
var command = "SELECT part, blob FROM blob WHERE id = ? AND " + var command = "SELECT part, blob FROM attachment WHERE id = ? AND " +
"attachment = ? AND part >= ?", "attachment = ? AND part >= ?",
argument_list = [id, name, start_index]; argument_list = [id, name, start_index];
......
This diff is collapsed.
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