Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
18
Merge Requests
18
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
jio
Commits
6ddd86f1
Commit
6ddd86f1
authored
Oct 09, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip indexeddb: use openCUrsor to fetch all blobs
parent
2d255b4e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
41 additions
and
39 deletions
+41
-39
src/jio.storage/indexeddbstorage.js
src/jio.storage/indexeddbstorage.js
+23
-34
test/jio.storage/indexeddbstorage.tests.js
test/jio.storage/indexeddbstorage.tests.js
+18
-5
No files found.
src/jio.storage/indexeddbstorage.js
View file @
6ddd86f1
...
...
@@ -389,7 +389,8 @@
}
var
db_name
=
this
.
_database_name
,
start
,
end
;
end
,
array_buffer_list
=
[];
start
=
options
.
start
||
0
;
end
=
options
.
end
;
...
...
@@ -399,25 +400,15 @@
return
waitForOpenIndexedDB
(
db_name
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
attachment
"
,
"
blob
"
],
"
readonly
"
,
function
(
tx
)
{
var
promise_list
,
key_path
=
buildKeyPath
([
id
,
name
]),
blob_store
;
var
key_path
=
buildKeyPath
([
id
,
name
]),
attachment_store
=
tx
.
objectStore
(
"
attachment
"
),
blob_store
=
tx
.
objectStore
(
"
blob
"
);
/*
start_index,
end_index,
i;
*/
promise_list
=
[
// Get the attachment info (mime type)
waitForIDBRequest
(
tx
.
objectStore
(
"
attachment
"
).
get
(
key_path
))
];
blob_store
=
tx
.
objectStore
(
"
blob
"
);
function
getBlob
(
cursor
)
{
var
index
=
parseInt
(
cursor
.
primaryKey
.
slice
(
key_path
.
length
+
1
),
...
...
@@ -425,27 +416,30 @@
),
i
=
index
;
// Extend array size
while
(
i
>
promise_list
.
length
-
1
)
{
promise
_list
.
push
(
null
);
while
(
i
>
array_buffer_list
.
length
)
{
array_buffer
_list
.
push
(
null
);
i
-=
1
;
}
// Sort the blob by their index
promise
_list
.
splice
(
index
+
1
,
array_buffer
_list
.
splice
(
index
,
0
,
waitForIDBRequest
(
blob_store
.
get
(
cursor
.
primaryKey
))
cursor
.
value
.
blob
);
}
// Get all needed blobs
return
waitForAllSynchronousCursor
(
blob_store
.
index
(
"
_id_attachment
"
)
.
openKeyCursor
(
IDBKeyRange
.
only
([
id
,
name
])),
getBlob
)
.
then
(
function
()
{
return
RSVP
.
all
(
promise_list
);
});
return
RSVP
.
all
([
// Get the attachment info (mime type)
waitForIDBRequest
(
attachment_store
.
get
(
key_path
)),
// Get all needed blobs
waitForAllSynchronousCursor
(
blob_store
.
index
(
"
_id_attachment
"
)
.
openCursor
(
IDBKeyRange
.
only
([
id
,
name
])),
getBlob
)
]);
});
});
...
...
@@ -488,9 +482,7 @@
// No need to keep the IDB open
var
blob
,
index
,
attachment
=
result_list
[
0
].
target
.
result
,
array_buffer_list
=
[],
i
;
attachment
=
result_list
[
0
].
target
.
result
;
// Should raise if key is not good
if
(
!
attachment
)
{
...
...
@@ -502,9 +494,6 @@
);
}
for
(
i
=
1
;
i
<
result_list
.
length
;
i
+=
1
)
{
array_buffer_list
.
push
(
result_list
[
i
].
target
.
result
.
blob
);
}
if
((
options
.
start
===
undefined
)
&&
(
options
.
end
===
undefined
))
{
blob
=
new
Blob
(
array_buffer_list
,
{
type
:
attachment
.
info
.
content_type
});
...
...
test/jio.storage/indexeddbstorage.tests.js
View file @
6ddd86f1
...
...
@@ -1223,6 +1223,8 @@
context
.
spy_index
=
sinon
.
spy
(
IDBObjectStore
.
prototype
,
"
index
"
);
context
.
spy_create_index
=
sinon
.
spy
(
IDBObjectStore
.
prototype
,
"
createIndex
"
);
context
.
spy_cursor
=
sinon
.
spy
(
IDBIndex
.
prototype
,
"
openCursor
"
);
context
.
spy_key_cursor
=
sinon
.
spy
(
IDBIndex
.
prototype
,
"
openKeyCursor
"
);
return
context
.
jio
.
getAttachment
(
"
foo
"
,
attachment
);
})
...
...
@@ -1252,17 +1254,24 @@
deepEqual
(
context
.
spy_store
.
secondCall
.
args
[
0
],
"
blob
"
,
"
store first argument
"
);
equal
(
context
.
spy_get
.
callCount
,
3
,
"
get count
"
+
equal
(
context
.
spy_get
.
callCount
,
1
,
"
get count
"
+
context
.
spy_get
.
callCount
);
deepEqual
(
context
.
spy_get
.
firstCall
.
args
[
0
],
"
foo_attachment
"
,
"
get first argument
"
);
deepEqual
(
context
.
spy_get
.
secondCall
.
args
[
0
],
"
foo_attachment_0
"
,
"
get first argument
"
);
deepEqual
(
context
.
spy_get
.
thirdCall
.
args
[
0
],
"
foo_attachment_1
"
,
"
get first argument
"
);
ok
(
context
.
spy_index
.
called
,
"
index count
"
+
context
.
spy_index
.
callCount
);
equal
(
context
.
spy_cursor
.
callCount
,
1
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
ok
(
!
context
.
spy_key_cursor
.
called
,
"
cursor key count
"
+
context
.
spy_key_cursor
.
callCount
);
ok
(
context
.
spy_key_range
.
calledOnce
,
"
key range count
"
+
context
.
spy_key_range
.
callCount
);
deepEqual
(
context
.
spy_key_range
.
firstCall
.
args
[
0
],
[
"
foo
"
,
"
attachment
"
],
"
key range first argument
"
);
})
.
always
(
function
()
{
context
.
spy_open
.
restore
();
...
...
@@ -1279,6 +1288,10 @@
delete
context
.
spy_index
;
context
.
spy_create_index
.
restore
();
delete
context
.
spy_create_index
;
context
.
spy_cursor
.
restore
();
delete
context
.
spy_cursor
;
context
.
spy_key_cursor
.
restore
();
delete
context
.
spy_key_cursor
;
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
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