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
e29efa38
Commit
e29efa38
authored
Oct 08, 2018
by
Romain Courteaud
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
wip indexeddb
parent
1f09d1ac
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
95 additions
and
57 deletions
+95
-57
src/jio.storage/indexeddbstorage.js
src/jio.storage/indexeddbstorage.js
+46
-43
test/jio.storage/indexeddbstorage.tests.js
test/jio.storage/indexeddbstorage.tests.js
+49
-14
No files found.
src/jio.storage/indexeddbstorage.js
View file @
e29efa38
...
...
@@ -346,25 +346,33 @@
return
waitForTransaction
(
db
,
[
"
metadata
"
,
"
attachment
"
,
"
blob
"
],
"
readwrite
"
,
function
(
tx
)
{
var
promise_list
=
[];
var
promise_list
=
[],
metadata_store
=
tx
.
objectStore
(
"
metadata
"
),
attachment_store
=
tx
.
objectStore
(
"
attachment
"
),
blob_store
=
tx
.
objectStore
(
"
blob
"
);
function
deleteEntry
(
cursor
)
{
function
deleteAttachment
(
cursor
)
{
promise_list
.
push
(
waitForIDBRequest
(
attachment_store
.
delete
(
cursor
.
primaryKey
))
);
}
function
deleteBlob
(
cursor
)
{
promise_list
.
push
(
waitForIDBRequest
(
cursor
.
delete
(
))
waitForIDBRequest
(
blob_store
.
delete
(
cursor
.
primaryKey
))
);
}
return
RSVP
.
all
([
waitForIDBRequest
(
tx
.
objectStore
(
"
metadata
"
).
delete
(
id
)),
// XXX Why not possible to delete with KeyCursor?
waitForIDBRequest
(
metadata_store
.
delete
(
id
)),
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
attachment
"
)
.
index
(
"
_id
"
)
.
open
Cursor
(
IDBKeyRange
.
only
(
id
)),
delete
Entry
attachment_store
.
index
(
"
_id
"
)
.
openKey
Cursor
(
IDBKeyRange
.
only
(
id
)),
delete
Attachment
),
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
blob
"
)
.
index
(
"
_id
"
)
.
open
Cursor
(
IDBKeyRange
.
only
(
id
)),
delete
Entry
blob_store
.
index
(
"
_id
"
)
.
openKey
Cursor
(
IDBKeyRange
.
only
(
id
)),
delete
Blob
),
])
.
then
(
function
()
{
...
...
@@ -498,7 +506,6 @@
array_buffer_list
.
push
(
result_list
[
i
].
target
.
result
.
blob
);
}
// total_length = attachment.info.length;
console
.
log
(
'
array_buffer_list
'
,
array_buffer_list
);
if
((
options
.
start
===
undefined
)
&&
(
options
.
end
===
undefined
))
{
return
new
Blob
(
array_buffer_list
,
{
type
:
attachment
.
info
.
content_type
});
...
...
@@ -511,30 +518,6 @@
};
function
removeAttachment
(
tx
,
id
,
name
)
{
var
promise_list
=
[];
function
deleteEntry
(
cursor
)
{
promise_list
.
push
(
waitForIDBRequest
(
cursor
.
delete
())
);
}
return
RSVP
.
all
([
waitForIDBRequest
(
tx
.
objectStore
(
"
attachment
"
).
delete
(
buildKeyPath
([
id
,
name
]))
),
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
blob
"
).
index
(
"
_id_attachment
"
)
.
openCursor
(
IDBKeyRange
.
only
([
id
,
name
])),
deleteEntry
)
])
.
then
(
function
()
{
return
RSVP
.
all
(
promise_list
);
});
}
IndexedDBStorage
.
prototype
.
putAttachment
=
function
(
id
,
name
,
blob
)
{
var
db_name
=
this
.
_database_name
;
return
new
RSVP
.
Queue
()
...
...
@@ -557,9 +540,6 @@
return
waitForOpenIndexedDB
(
db_name
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
attachment
"
,
"
blob
"
],
"
readwrite
"
,
function
(
tx
)
{
// First remove the previous attachment
// return removeAttachment(tx, id, name)
// .then(function () {
var
blob_store
,
promise_list
,
delete_promise_list
=
[],
...
...
@@ -598,7 +578,7 @@
);
if
(
index
>
blob_part
.
length
+
1
)
{
delete_promise_list
.
push
(
waitForIDBRequest
(
cursor
.
delete
(
))
waitForIDBRequest
(
blob_store
.
delete
(
cursor
.
primaryKey
))
);
}
}
...
...
@@ -606,8 +586,8 @@
// Finally, remove all remaining blobs
promise_list
.
push
(
waitForAllSynchronousCursor
(
tx
.
objectStore
(
"
blob
"
)
.
index
(
"
_id_attachment
"
)
.
open
Cursor
(
IDBKeyRange
.
only
([
id
,
name
])),
blob_store
.
index
(
"
_id_attachment
"
)
.
openKey
Cursor
(
IDBKeyRange
.
only
([
id
,
name
])),
deleteEntry
)
);
...
...
@@ -628,7 +608,30 @@
return
waitForOpenIndexedDB
(
this
.
_database_name
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
attachment
"
,
"
blob
"
],
"
readwrite
"
,
function
(
tx
)
{
return
removeAttachment
(
tx
,
id
,
name
);
var
promise_list
=
[],
attachment_store
=
tx
.
objectStore
(
"
attachment
"
),
blob_store
=
tx
.
objectStore
(
"
blob
"
);
function
deleteEntry
(
cursor
)
{
promise_list
.
push
(
waitForIDBRequest
(
blob_store
.
delete
(
cursor
.
primaryKey
))
);
}
return
RSVP
.
all
([
waitForIDBRequest
(
attachment_store
.
delete
(
buildKeyPath
([
id
,
name
]))
),
waitForAllSynchronousCursor
(
blob_store
.
index
(
"
_id_attachment
"
)
.
openKeyCursor
(
IDBKeyRange
.
only
([
id
,
name
])),
deleteEntry
)
])
.
then
(
function
()
{
return
RSVP
.
all
(
promise_list
);
});
});
});
};
...
...
test/jio.storage/indexeddbstorage.tests.js
View file @
e29efa38
...
...
@@ -942,7 +942,7 @@
test
(
"
spy indexedDB usage with one document
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
2
1
);
expect
(
2
2
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
...
...
@@ -960,6 +960,7 @@
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
"
);
context
.
spy_cursor_delete
=
sinon
.
spy
(
IDBCursor
.
prototype
,
"
delete
"
);
context
.
spy_key_range
=
sinon
.
spy
(
IDBKeyRange
,
"
only
"
);
...
...
@@ -1005,9 +1006,11 @@
deepEqual
(
context
.
spy_index
.
secondCall
.
args
[
0
],
"
_id
"
,
"
index first argument
"
);
ok
(
context
.
spy_cursor
.
calledTwice
,
"
cursor count
"
+
equal
(
context
.
spy_cursor
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
equal
(
context
.
spy_cursor_delete
.
callCount
,
0
,
"
cursor count
"
+
ok
(
context
.
spy_key_cursor
.
calledTwice
,
"
cursor key count
"
+
context
.
spy_key_cursor
.
callCount
);
equal
(
context
.
spy_cursor_delete
.
callCount
,
0
,
"
cursor delete count
"
+
context
.
spy_cursor_delete
.
callCount
);
ok
(
context
.
spy_key_range
.
calledTwice
,
"
key range count
"
+
...
...
@@ -1033,6 +1036,8 @@
delete
context
.
spy_index
;
context
.
spy_create_index
.
restore
();
delete
context
.
spy_create_index
;
context
.
spy_key_cursor
.
restore
();
delete
context
.
spy_key_cursor
;
context
.
spy_cursor
.
restore
();
delete
context
.
spy_cursor
;
context
.
spy_cursor_delete
.
restore
();
...
...
@@ -1051,7 +1056,7 @@
test
(
"
spy indexedDB usage with 2 attachments
"
,
function
()
{
var
context
=
this
;
stop
();
expect
(
2
1
);
expect
(
2
6
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
...
...
@@ -1075,6 +1080,7 @@
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
"
);
context
.
spy_cursor_delete
=
sinon
.
spy
(
IDBCursor
.
prototype
,
"
delete
"
);
context
.
spy_key_range
=
sinon
.
spy
(
IDBKeyRange
,
"
only
"
);
...
...
@@ -1107,10 +1113,18 @@
deepEqual
(
context
.
spy_store
.
thirdCall
.
args
[
0
],
"
blob
"
,
"
store first argument
"
);
equal
(
context
.
spy_delete
.
callCount
,
1
,
"
delete count
"
+
equal
(
context
.
spy_delete
.
callCount
,
5
,
"
delete count
"
+
context
.
spy_delete
.
callCount
);
deepEqual
(
context
.
spy_delete
.
firstCall
.
args
[
0
],
"
foo
"
,
"
delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
secondCall
.
args
[
0
],
"
foo_attachment1
"
,
"
second delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
thirdCall
.
args
[
0
],
"
foo_attachment1_0
"
,
"
third delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
getCall
(
3
).
args
[
0
],
"
foo_attachment2
"
,
"
fourth delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
getCall
(
4
).
args
[
0
],
"
foo_attachment2_0
"
,
"
fifth delete first argument
"
);
ok
(
context
.
spy_index
.
calledTwice
,
"
index count
"
+
context
.
spy_index
.
callCount
);
...
...
@@ -1119,10 +1133,12 @@
deepEqual
(
context
.
spy_index
.
secondCall
.
args
[
0
],
"
_id
"
,
"
index first argument
"
);
ok
(
context
.
spy_cursor
.
calledTwice
,
"
cursor count
"
+
equal
(
context
.
spy_cursor
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
ok
(
context
.
spy_key_cursor
.
calledTwice
,
"
cursor key count
"
+
context
.
spy_key_cursor
.
callCount
);
equal
(
context
.
spy_cursor_delete
.
callCount
,
4
,
"
cursor count
"
+
equal
(
context
.
spy_cursor_delete
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor_delete
.
callCount
);
ok
(
context
.
spy_key_range
.
calledTwice
,
"
key range count
"
+
...
...
@@ -1148,6 +1164,8 @@
delete
context
.
spy_index
;
context
.
spy_create_index
.
restore
();
delete
context
.
spy_create_index
;
context
.
spy_key_cursor
.
restore
();
delete
context
.
spy_key_cursor
;
context
.
spy_cursor
.
restore
();
delete
context
.
spy_cursor
;
context
.
spy_cursor_delete
.
restore
();
...
...
@@ -1435,7 +1453,7 @@
var
context
=
this
,
attachment
=
"
attachment
"
;
stop
();
expect
(
17
);
expect
(
20
);
deleteIndexedDB
(
context
.
jio
)
.
then
(
function
()
{
...
...
@@ -1457,6 +1475,7 @@
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
"
);
context
.
spy_cursor_delete
=
sinon
.
spy
(
IDBCursor
.
prototype
,
"
delete
"
);
context
.
spy_key_range
=
sinon
.
spy
(
IDBKeyRange
,
"
only
"
);
...
...
@@ -1489,17 +1508,23 @@
deepEqual
(
context
.
spy_store
.
secondCall
.
args
[
0
],
"
blob
"
,
"
store first argument
"
);
equal
(
context
.
spy_delete
.
callCount
,
1
,
"
delete count
"
+
equal
(
context
.
spy_delete
.
callCount
,
3
,
"
delete count
"
+
context
.
spy_delete
.
callCount
);
deepEqual
(
context
.
spy_delete
.
firstCall
.
args
[
0
],
"
foo_attachment
"
,
"
delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
secondCall
.
args
[
0
],
"
foo_attachment_0
"
,
"
second delete first argument
"
);
deepEqual
(
context
.
spy_delete
.
thirdCall
.
args
[
0
],
"
foo_attachment_1
"
,
"
third delete first argument
"
);
ok
(
context
.
spy_index
.
calledOnce
,
"
index count
"
+
context
.
spy_index
.
callCount
);
ok
(
context
.
spy_cursor
.
calledOnce
,
"
cursor count
"
+
equal
(
context
.
spy_cursor
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
equal
(
context
.
spy_cursor_delete
.
callCount
,
2
,
"
cursor count
"
+
ok
(
context
.
spy_key_cursor
.
calledOnce
,
"
cursor key count
"
+
context
.
spy_key_cursor
.
callCount
);
equal
(
context
.
spy_cursor_delete
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor_delete
.
callCount
);
ok
(
context
.
spy_key_range
.
calledOnce
,
"
key range count
"
+
...
...
@@ -1525,6 +1550,8 @@
delete
context
.
spy_create_index
;
context
.
spy_cursor
.
restore
();
delete
context
.
spy_cursor
;
context
.
spy_key_cursor
.
restore
();
delete
context
.
spy_key_cursor
;
context
.
spy_cursor_delete
.
restore
();
delete
context
.
spy_cursor_delete
;
context
.
spy_key_range
.
restore
();
...
...
@@ -1560,6 +1587,9 @@
.
then
(
function
()
{
return
context
.
jio
.
put
(
"
foo
"
,
{
"
title
"
:
"
bar
"
});
})
.
then
(
function
()
{
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
})
.
then
(
function
()
{
context
.
spy_open
=
sinon
.
spy
(
indexedDB
,
"
open
"
);
context
.
spy_create_store
=
sinon
.
spy
(
IDBDatabase
.
prototype
,
...
...
@@ -1573,10 +1603,11 @@
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
"
);
context
.
spy_cursor_delete
=
sinon
.
spy
(
IDBCursor
.
prototype
,
"
delete
"
);
context
.
spy_key_range
=
sinon
.
spy
(
IDBKeyRange
,
"
only
"
);
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
big_string
);
return
context
.
jio
.
putAttachment
(
"
foo
"
,
attachment
,
'
small_string
'
);
})
.
fail
(
function
(
error
)
{
ok
(
false
,
error
);
...
...
@@ -1613,17 +1644,19 @@
deepEqual(context.spy_store.getCall(3).args[0], "blob",
"store first argument");
*/
equal
(
context
.
spy_delete
.
callCount
,
0
,
"
delete count
"
+
equal
(
context
.
spy_delete
.
callCount
,
11
0
,
"
delete count
"
+
context
.
spy_delete
.
callCount
);
/*
deepEqual(context.spy_delete.firstCall.args[0], "foo_attachment",
"delete first argument");
*/
equal
(
context
.
spy_index
.
callCount
,
0
,
"
index count
"
+
equal
(
context
.
spy_index
.
callCount
,
1
,
"
index count
"
+
context
.
spy_index
.
callCount
);
equal
(
context
.
spy_cursor
.
callCount
,
0
,
"
cursor count
"
+
context
.
spy_cursor
.
callCount
);
equal
(
context
.
spy_key_cursor
.
callCount
,
1
,
"
cursor count
"
+
context
.
spy_key_cursor
.
callCount
);
/*
equal(context.spy_cursor_delete.callCount, 0, "delete count " +
context.spy_cursor_delete.callCount);
...
...
@@ -1678,6 +1711,8 @@
delete
context
.
spy_create_index
;
context
.
spy_cursor
.
restore
();
delete
context
.
spy_cursor
;
context
.
spy_key_cursor
.
restore
();
delete
context
.
spy_key_cursor
;
context
.
spy_cursor_delete
.
restore
();
delete
context
.
spy_cursor_delete
;
context
.
spy_key_range
.
restore
();
...
...
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