Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
J
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Cédric Le Ninivin
jio
Commits
7cd55e13
Commit
7cd55e13
authored
Nov 17, 2016
by
Cédric Le Ninivin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ReplicateStorage: Code improvment
parent
829a447c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
36 additions
and
43 deletions
+36
-43
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+36
-43
No files found.
src/jio.storage/replicatestorage.js
View file @
7cd55e13
...
@@ -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_attachment
s
:
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_attachment
s
===
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_attachment
s
:
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
]
=
evt
.
target
.
result
generateHashFromArrayBuffer
(
);
evt
.
target
.
result
})
);
.
push
(
function
(
hash
)
{
hash_document
.
attachments_hash
[
attachment_id
]
=
hash
;
hash_document
.
updated
=
true
;
hash_document
.
updated
=
true
;
return
;
return
;
});
});
...
@@ -379,11 +377,11 @@
...
@@ -379,11 +377,11 @@
});
});
}
}
function
copyDocumentAndAttachment
s
(
source
,
destination
,
function
copyDocumentAndAttachment
List
(
source
,
destination
,
source_id
,
destination_id
,
source_id
,
destination_id
,
doc
,
doc
,
hash_document
,
hash_document
,
garbage_collect
)
{
garbage_collect
)
{
if
(
garbage_collect
===
undefined
)
{
if
(
garbage_collect
===
undefined
)
{
garbage_collect
=
false
;
garbage_collect
=
false
;
}
}
...
@@ -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_attachment
s
:
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_attachment
s
:
true
skip_attachment
_list
:
true
};
};
return
context
.
_signature_sub_storage
.
remove
(
source_id
);
return
context
.
_signature_sub_storage
.
remove
(
source_id
);
}
}
...
@@ -460,17 +458,17 @@
...
@@ -460,17 +458,17 @@
};
};
post_id
=
new_id
;
post_id
=
new_id
;
signature_dict
[
post_id
]
=
hash_document
;
signature_dict
[
post_id
]
=
hash_document
;
return
copyDocumentAndAttachment
s
(
source
,
source
,
return
copyDocumentAndAttachment
List
(
source
,
source
,
id
,
post_id
,
id
,
post_id
,
doc
,
doc
,
hash_document
,
hash_document
,
true
);
true
);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
copyDocumentAndAttachment
s
(
source
,
destination
,
return
copyDocumentAndAttachment
List
(
source
,
destination
,
post_id
,
post_id
,
post_id
,
post_id
,
doc
,
doc
,
signature_dict
[
post_id
]);
signature_dict
[
post_id
]);
})
})
.
push
(
function
()
{
.
push
(
function
()
{
return
post_id
;
return
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_attachment
s
:
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_attachment
s
:
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_attachment
s
:
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
()
return
jIO
.
util
.
readBlobAsArrayBuffer
(
attachment_blob
);
.
push
(
function
()
{
return
jIO
.
util
.
readBlobAsArrayBuffer
(
attachment_blob
);
})
.
push
(
function
(
evt
)
{
return
generateHashFromArrayBuffer
(
evt
.
target
.
result
);
});
})
})
.
push
(
function
(
local_hash
)
{
.
push
(
function
(
evt
)
{
var
status_hash
=
attachment_signature_dict
[
attachment_id
];
var
status_hash
=
attachment_signature_dict
[
attachment_id
],
local_hash
=
generateHashFromArrayBuffer
(
evt
.
target
.
result
);
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
copyDocumentAndAttachment
s
(
return
copyDocumentAndAttachment
List
(
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_attachment
s
===
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_attachment
s
===
true
)
{
&&
skip_document_dict
.
skip_attachment
_list
===
true
)
{
// No attachments to check
// No attachments to check
return
{};
return
{};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment