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
Vincent Bechu
jio
Commits
4f5abd39
Commit
4f5abd39
authored
Apr 11, 2017
by
Vincent Bechu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
replicatestorage: limit calculation hash for attachment
parent
603f4dda
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
154 additions
and
6 deletions
+154
-6
src/jio.storage/replicatestorage.js
src/jio.storage/replicatestorage.js
+15
-3
test/jio.storage/replicatestorage.tests.js
test/jio.storage/replicatestorage.tests.js
+139
-3
No files found.
src/jio.storage/replicatestorage.js
View file @
4f5abd39
...
@@ -39,8 +39,11 @@
...
@@ -39,8 +39,11 @@
return
rusha
.
digestFromString
(
content
);
return
rusha
.
digestFromString
(
content
);
}
}
function
generateHashFromArrayBuffer
(
content
)
{
function
generateHashFromArrayBuffer
(
content
,
context
)
{
// XXX Improve performance by moving calculation to WebWorker
// XXX Improve performance by moving calculation to WebWorker
if
(
context
.
_skip_attachment_hash
)
{
return
"
1
"
;
}
return
rusha
.
digestFromArrayBuffer
(
content
);
return
rusha
.
digestFromArrayBuffer
(
content
);
}
}
...
@@ -145,6 +148,14 @@
...
@@ -145,6 +148,14 @@
if
(
this
.
_check_remote_attachment_deletion
===
undefined
)
{
if
(
this
.
_check_remote_attachment_deletion
===
undefined
)
{
this
.
_check_remote_attachment_deletion
=
false
;
this
.
_check_remote_attachment_deletion
=
false
;
}
}
this
.
_skip_attachment_hash
=
!
this
.
_check_remote_attachment_modification
&&
!
this
.
_check_local_attachment_modification
&&
((
!
this
.
_check_local_attachment_creation
&&
this
.
_conflict_handling
!==
CONFLICT_KEEP_LOCAL
)
||
(
!
this
.
_check_remote_attachment_creation
&&
this
.
_conflict_handling
!==
CONFLICT_KEEP_REMOTE
));
}
}
ReplicateStorage
.
prototype
.
remove
=
function
(
id
)
{
ReplicateStorage
.
prototype
.
remove
=
function
(
id
)
{
...
@@ -282,7 +293,8 @@
...
@@ -282,7 +293,8 @@
})
})
.
push
(
function
(
evt
)
{
.
push
(
function
(
evt
)
{
return
generateHashFromArrayBuffer
(
return
generateHashFromArrayBuffer
(
evt
.
target
.
result
evt
.
target
.
result
,
context
);
);
},
function
(
error
)
{
},
function
(
error
)
{
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
if
((
error
instanceof
jIO
.
util
.
jIOError
)
&&
...
@@ -400,7 +412,7 @@
...
@@ -400,7 +412,7 @@
})
})
.
push
(
function
(
evt
)
{
.
push
(
function
(
evt
)
{
var
array_buffer
=
evt
.
target
.
result
,
var
array_buffer
=
evt
.
target
.
result
,
local_hash
=
generateHashFromArrayBuffer
(
array_buffer
);
local_hash
=
generateHashFromArrayBuffer
(
array_buffer
,
context
);
if
(
local_hash
!==
status_hash
)
{
if
(
local_hash
!==
status_hash
)
{
return
checkAndPropagateAttachment
(
skip_attachment_dict
,
return
checkAndPropagateAttachment
(
skip_attachment_dict
,
...
...
test/jio.storage/replicatestorage.tests.js
View file @
4f5abd39
...
@@ -4947,7 +4947,7 @@
...
@@ -4947,7 +4947,7 @@
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
hash
:
"
cd762363c1c11ecb48611583520bba111f0034d4
"
hash
:
"
1
"
});
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
...
@@ -5967,7 +5967,7 @@
...
@@ -5967,7 +5967,7 @@
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
hash
:
"
cd762363c1c11ecb48611583520bba111f0034d4
"
hash
:
"
1
"
});
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
...
@@ -6103,7 +6103,7 @@
...
@@ -6103,7 +6103,7 @@
})
})
.
then
(
function
(
result
)
{
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
deepEqual
(
result
,
{
hash
:
"
cd762363c1c11ecb48611583520bba111f0034d4
"
hash
:
"
1
"
});
});
})
})
.
fail
(
function
(
error
)
{
.
fail
(
function
(
error
)
{
...
@@ -8276,4 +8276,140 @@
...
@@ -8276,4 +8276,140 @@
});
});
});
});
test
(
"
local creation same attachment, keep remote
"
,
function
()
{
stop
();
expect
(
2
);
var
id
,
context
=
this
,
blob
=
new
Blob
([
big_string
]),
blob2
=
new
Blob
([
big_string
+
"
a
"
]);
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
conflict_handling
:
2
,
check_local_attachment_creation
:
true
,
local_sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
context
.
jio
.
post
({
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
id
=
result
;
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
putAttachment
(
id
,
"
foo
"
,
blob
);
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
id
,
"
foo
"
,
blob2
);
})
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
getAttachment
(
id
,
"
foo
"
,
{
format
:
"
text
"
}
);
})
.
then
(
function
(
result
)
{
equal
(
result
,
big_string
);
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
getAttachment
(
id
,
"
foo
"
,
{
format
:
"
json
"
});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
cd762363c1c11ecb48611583520bba111f0034d4
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
test
(
"
remote creation same attachment, keep local
"
,
function
()
{
stop
();
expect
(
2
);
var
id
,
context
=
this
,
blob
=
new
Blob
([
big_string
]),
blob2
=
new
Blob
([
big_string
+
"
a
"
]);
this
.
jio
=
jIO
.
createJIO
({
type
:
"
replicate
"
,
conflict_handling
:
1
,
check_remote_attachment_creation
:
true
,
local_sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
},
remote_sub_storage
:
{
type
:
"
uuid
"
,
sub_storage
:
{
type
:
"
memory
"
}
}
});
context
.
jio
.
post
({
"
title
"
:
"
foo
"
})
.
then
(
function
(
result
)
{
id
=
result
;
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
putAttachment
(
id
,
"
foo
"
,
blob2
);
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
id
,
"
foo
"
,
blob
);
})
.
then
(
function
()
{
return
context
.
jio
.
repair
();
})
.
then
(
function
()
{
return
context
.
jio
.
__storage
.
_remote_sub_storage
.
getAttachment
(
id
,
"
foo
"
,
{
format
:
"
text
"
}
);
})
.
then
(
function
(
result
)
{
equal
(
result
,
big_string
);
return
context
.
jio
.
__storage
.
_signature_sub_storage
.
getAttachment
(
id
,
"
foo
"
,
{
format
:
"
json
"
});
})
.
then
(
function
(
result
)
{
deepEqual
(
result
,
{
hash
:
"
cd762363c1c11ecb48611583520bba111f0034d4
"
});
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
})
.
always
(
function
()
{
start
();
});
});
}(
jIO
,
QUnit
,
Blob
,
RSVP
));
}(
jIO
,
QUnit
,
Blob
,
RSVP
));
\ No newline at end of file
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