Commit 2b211fb4 authored by Boris Kocherov's avatar Boris Kocherov

Revert "working but bad solution of "transaction close on onsuccess callback ended" problem."

This reverts commit 357d923c.
nexedi/rsvp.js!1 fix it by more elegant way
parent 8a325540
...@@ -303,7 +303,8 @@ ...@@ -303,7 +303,8 @@
}; };
IndexedDBStorage.prototype.getAttachment = function (id, name, options) { IndexedDBStorage.prototype.getAttachment = function (id, name, options) {
var type, var transaction,
type,
start, start,
end; end;
if (options === undefined) { if (options === undefined) {
...@@ -311,63 +312,48 @@ ...@@ -311,63 +312,48 @@
} }
return openIndexedDB(this) return openIndexedDB(this)
.push(function (db) { .push(function (db) {
return new RSVP.Promise(function (resolve, reject) { transaction = openTransaction(db, ["attachment", "blob"], "readonly");
var transaction = openTransaction(db, ["attachment", "blob"], // XXX Should raise if key is not good
"readonly"), return handleGet(transaction.objectStore("attachment")
// XXX Should raise if key is not good .get(buildKeyPath([id, name])));
request = transaction.objectStore("attachment") })
.get(buildKeyPath([id, name])); .push(function (attachment) {
request.onerror = function (error) { var total_length = attachment.info.length,
transaction.abort(); i,
reject(error); promise_list = [],
}; store = transaction.objectStore("blob"),
request.onsuccess = function () { start_index,
var attachment = request.result, end_index;
total_length,
i, type = attachment.info.content_type;
promise_list = [], start = options.start || 0;
store = transaction.objectStore("blob"), end = options.end || total_length;
start_index, if (end > total_length) {
end_index; end = total_length;
}
if (!attachment) {
return reject( if (start < 0 || end < 0) {
new jIO.util.jIOError("Cannot find attachment", 404) throw new jIO.util.jIOError("_start and _end must be positive",
); 400);
} }
if (start > end) {
total_length = attachment.info.length; throw new jIO.util.jIOError("_start is greater than _end",
type = attachment.info.content_type; 400);
start = options.start || 0; }
end = options.end || total_length;
if (end > total_length) { start_index = Math.floor(start / UNITE);
end = total_length; end_index = Math.floor(end / UNITE);
} if (end % UNITE === 0) {
end_index -= 1;
if (start < 0 || end < 0) { }
throw new jIO.util.jIOError("_start and _end must be positive",
400); for (i = start_index; i <= end_index; i += 1) {
} promise_list.push(
if (start > end) { handleGet(store.get(buildKeyPath([id,
throw new jIO.util.jIOError("_start is greater than _end", name, i])))
400); );
} }
return RSVP.all(promise_list);
start_index = Math.floor(start / UNITE);
end_index = Math.floor(end / UNITE);
if (end % UNITE === 0) {
end_index -= 1;
}
for (i = start_index; i <= end_index; i += 1) {
promise_list.push(
handleGet(store.get(buildKeyPath([id,
name, i])))
);
}
resolve(RSVP.all(promise_list));
};
});
}) })
.push(function (result_list) { .push(function (result_list) {
var array_buffer_list = [], var array_buffer_list = [],
...@@ -427,12 +413,10 @@ ...@@ -427,12 +413,10 @@
} }
// Remove previous attachment // Remove previous attachment
transaction = openTransaction(db, ["attachment", "blob"], transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
"readwrite", false);
return removeAttachment(transaction, id, name); return removeAttachment(transaction, id, name);
}) })
.push(function () { .push(function () {
transaction = openTransaction(db, ["attachment", "blob"], "readwrite");
var promise_list = [ var promise_list = [
handleRequest(transaction.objectStore("attachment").put({ handleRequest(transaction.objectStore("attachment").put({
......
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