Commit 7cd55e13 authored by Cédric Le Ninivin's avatar Cédric Le Ninivin

ReplicateStorage: Code improvment

parent 829a447c
...@@ -213,7 +213,7 @@ ...@@ -213,7 +213,7 @@
// Do not sync the signature document // Do not sync the signature document
skip_document_dict[context._signature_hash] = { skip_document_dict[context._signature_hash] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
function allAttachmentMethod(storage, id) { function allAttachmentMethod(storage, id) {
...@@ -232,7 +232,7 @@ ...@@ -232,7 +232,7 @@
&& skip_document_dict[id].skip === true; && skip_document_dict[id].skip === true;
} }
return skip_document_dict[id] !== undefined return skip_document_dict[id] !== undefined
&& (skip_document_dict[id].skip_attachments === true && (skip_document_dict[id].skip_attachment_list === true
|| (skip_document_dict[id].attachments !== undefined || (skip_document_dict[id].attachments !== undefined
&& skip_document_dict[id].attachments[attachment_id] === true)); && skip_document_dict[id].attachments[attachment_id] === true));
} }
...@@ -241,7 +241,7 @@ ...@@ -241,7 +241,7 @@
if (skip_document_dict[id] === undefined) { if (skip_document_dict[id] === undefined) {
skip_document_dict[id] = { skip_document_dict[id] = {
skip: false, skip: false,
skip_attachments: false, skip_attachment_list: false,
attachments: {} attachments: {}
}; };
} }
...@@ -276,9 +276,9 @@ ...@@ -276,9 +276,9 @@
return jIO.util.readBlobAsArrayBuffer(attachment_blob); return jIO.util.readBlobAsArrayBuffer(attachment_blob);
}) })
.push(function (evt) { .push(function (evt) {
return generateHashFromArrayBuffer(evt.target.result); var remote_hash = generateHashFromArrayBuffer(
}) evt.target.result
.push(function (remote_hash) { );
if (remote_hash === status_hash) { if (remote_hash === status_hash) {
// No modification. Attachment can be removed. // No modification. Attachment can be removed.
return destination.removeAttachment(id, attachment_id) return destination.removeAttachment(id, attachment_id)
...@@ -351,12 +351,10 @@ ...@@ -351,12 +351,10 @@
return jIO.util.readBlobAsArrayBuffer(attachment_blob); return jIO.util.readBlobAsArrayBuffer(attachment_blob);
}) })
.push(function (evt) { .push(function (evt) {
return generateHashFromArrayBuffer( hash_document.attachments_hash[attachment_id] =
generateHashFromArrayBuffer(
evt.target.result evt.target.result
); );
})
.push(function (hash) {
hash_document.attachments_hash[attachment_id] = hash;
hash_document.updated = true; hash_document.updated = true;
return; return;
}); });
...@@ -379,7 +377,7 @@ ...@@ -379,7 +377,7 @@
}); });
} }
function copyDocumentAndAttachments(source, destination, function copyDocumentAndAttachmentList(source, destination,
source_id, destination_id, source_id, destination_id,
doc, doc,
hash_document, hash_document,
...@@ -422,7 +420,7 @@ ...@@ -422,7 +420,7 @@
if (source_id === destination_id) { if (source_id === destination_id) {
skip_document_dict[destination_id] = { skip_document_dict[destination_id] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
} }
if (garbage_collect === true) { if (garbage_collect === true) {
...@@ -435,7 +433,7 @@ ...@@ -435,7 +433,7 @@
delete signature_dict[source_id]; delete signature_dict[source_id];
skip_document_dict[source_id] = { skip_document_dict[source_id] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
return context._signature_sub_storage.remove(source_id); return context._signature_sub_storage.remove(source_id);
} }
...@@ -460,14 +458,14 @@ ...@@ -460,14 +458,14 @@
}; };
post_id = new_id; post_id = new_id;
signature_dict[post_id] = hash_document; signature_dict[post_id] = hash_document;
return copyDocumentAndAttachments(source, source, return copyDocumentAndAttachmentList(source, source,
id, post_id, id, post_id,
doc, doc,
hash_document, hash_document,
true); true);
}) })
.push(function () { .push(function () {
return copyDocumentAndAttachments(source, destination, return copyDocumentAndAttachmentList(source, destination,
post_id, post_id, post_id, post_id,
doc, doc,
signature_dict[post_id]); signature_dict[post_id]);
...@@ -567,7 +565,7 @@ ...@@ -567,7 +565,7 @@
.push(function () { .push(function () {
skip_document_dict[id] = { skip_document_dict[id] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
return; return;
}); });
...@@ -597,7 +595,7 @@ ...@@ -597,7 +595,7 @@
signature_dict[id].updated = true; signature_dict[id].updated = true;
skip_document_dict[id] = { skip_document_dict[id] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
return; return;
}); });
...@@ -610,7 +608,7 @@ ...@@ -610,7 +608,7 @@
.push(function () { .push(function () {
skip_document_dict[id] = { skip_document_dict[id] = {
skip: true, skip: true,
skip_attachments: true skip_attachment_list: true
}; };
delete signature_dict[id]; delete signature_dict[id];
return; return;
...@@ -647,16 +645,11 @@ ...@@ -647,16 +645,11 @@
.push(function (result) { .push(function (result) {
attachment_blob = result; attachment_blob = result;
// Calculate Attachment Hash // Calculate Attachment Hash
return new RSVP.Queue()
.push(function () {
return jIO.util.readBlobAsArrayBuffer(attachment_blob); return jIO.util.readBlobAsArrayBuffer(attachment_blob);
}) })
.push(function (evt) { .push(function (evt) {
return generateHashFromArrayBuffer(evt.target.result); var status_hash = attachment_signature_dict[attachment_id],
}); local_hash = generateHashFromArrayBuffer(evt.target.result);
})
.push(function (local_hash) {
var status_hash = attachment_signature_dict[attachment_id];
if (local_hash !== status_hash) { if (local_hash !== status_hash) {
// Local modification // Local modification
return destination.getAttachment(id, attachment_id, return destination.getAttachment(id, attachment_id,
...@@ -708,7 +701,7 @@ ...@@ -708,7 +701,7 @@
// attachment to a non-existent attachment. // attachment to a non-existent attachment.
if ((error instanceof jIO.util.jIOError) && if ((error instanceof jIO.util.jIOError) &&
(error.status_code === 404)) { (error.status_code === 404)) {
return copyDocumentAndAttachments( return copyDocumentAndAttachmentList(
source, source,
destination, destination,
id, id,
...@@ -748,7 +741,7 @@ ...@@ -748,7 +741,7 @@
var hash_document; var hash_document;
if (skip_document_dict[id] !== undefined if (skip_document_dict[id] !== undefined
&& skip_document_dict[id].skip === true && skip_document_dict[id].skip === true
&& skip_document_dict[id].skip_attachments === true) { && skip_document_dict[id].skip_attachment_list === true) {
return; return;
} }
queue queue
...@@ -834,7 +827,7 @@ ...@@ -834,7 +827,7 @@
id = current_id; id = current_id;
hash_document = signature_dict[id]; hash_document = signature_dict[id];
if (skip_document_dict[id] !== undefined if (skip_document_dict[id] !== undefined
&& skip_document_dict.skip_attachments === true) { && skip_document_dict.skip_attachment_list === true) {
// No attachments to check // No attachments to check
return {}; return {};
} }
......
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