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
preetwinder
jio
Commits
0cbb66e4
Commit
0cbb66e4
authored
Mar 20, 2019
by
preetwinder
2
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change version change behavior
parent
1c97dccf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
84 additions
and
74 deletions
+84
-74
src/jio.storage/indexstorage2.js
src/jio.storage/indexstorage2.js
+24
-74
test/jio.storage/indexstorage2.tests.js
test/jio.storage/indexstorage2.tests.js
+60
-0
No files found.
src/jio.storage/indexstorage2.js
View file @
0cbb66e4
...
...
@@ -44,6 +44,7 @@
this
.
_use_sub_storage_query_partial
=
description
.
use_sub_storage_query_partial
;
}
this
.
_version
=
description
.
version
||
undefined
;
}
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
...
...
@@ -59,21 +60,6 @@
}
};
function
checkArrayEquality
(
array1
,
array2
)
{
if
(
array1
.
length
!==
array2
.
length
)
{
return
false
;
}
var
i
;
array1
=
array1
.
sort
();
array2
=
array2
.
sort
();
for
(
i
=
0
;
i
<
array1
.
length
;
i
+=
1
)
{
if
(
array1
[
i
]
!==
array2
[
i
])
{
return
false
;
}
}
return
true
;
}
function
compareSortOn
(
value1
,
value2
,
sort_on
)
{
var
current_compare
=
sort_on
.
slice
(
0
,
1
)[
0
],
remaining_compare
=
sort_on
.
slice
(
1
);
...
...
@@ -148,10 +134,10 @@
reject
(
"
Connection to:
"
+
db_name
+
"
timeout
"
);
};
request
.
onblocked
=
function
()
{
request
.
result
.
close
();
reject
(
"
Connection to:
"
+
db_name
+
"
was blocked
"
);
};
//
request.onblocked = function () {
//
request.result.close();
//
reject("Connection to: " + db_name + " was blocked");
//
};
Romain Courteaud
@romain
·
Mar 21, 2019
@preet
why did you comment this part?
@preet why did you comment this part?
Please
register
or
sign in
to reply
// Create DB if necessary //
request
.
onupgradeneeded
=
function
(
evt
)
{
...
...
@@ -181,35 +167,6 @@
return
new
RSVP
.
Promise
(
resolver
);
}
function
waitForUpdatedOpenIndexedDB
(
db_name
,
index_keys
,
callback
)
{
function
resolver
(
resolve
,
reject
)
{
var
db_version
,
store
,
current_indices
,
required_indices
;
required_indices
=
index_keys
.
map
(
function
(
value
)
{
return
'
Index-
'
+
value
;
}
);
waitForOpenIndexedDB
(
db_name
,
undefined
,
index_keys
,
function
(
db
)
{
db_version
=
db
.
version
;
store
=
db
.
transaction
(
'
index-store
'
).
objectStore
(
'
index-store
'
);
current_indices
=
store
.
indexNames
;
if
(
checkArrayEquality
(
required_indices
,
Array
.
from
(
current_indices
)))
{
resolve
(
callback
(
db
));
}
else
{
store
.
transaction
.
oncomplete
=
function
()
{
waitForOpenIndexedDB
(
db_name
,
db_version
+
1
,
index_keys
,
function
(
db
)
{
resolve
(
callback
(
db
));
});
};
}
})
.
fail
(
function
(
error
)
{
reject
(
error
);
});
}
return
new
RSVP
.
Promise
(
resolver
);
}
function
waitForTransaction
(
db
,
stores
,
flag
,
callback
)
{
var
tx
=
db
.
transaction
(
stores
,
flag
);
function
canceller
()
{
...
...
@@ -295,7 +252,7 @@
"
' key and checking the substorage for partial queries is not set
"
,
404
);
}
return
waitFor
UpdatedOpenIndexedDB
(
context
.
_database_name
,
return
waitFor
OpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
function
(
tx
)
{
...
...
@@ -397,7 +354,7 @@
});
});
}
return
waitFor
UpdatedOpenIndexedDB
(
context
.
_database_name
,
return
waitFor
OpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
function
(
tx
)
{
...
...
@@ -428,20 +385,25 @@
return
this
.
_sub_storage
.
get
.
apply
(
this
.
_sub_storage
,
arguments
);
};
IndexStorage2
.
prototype
.
_put
=
function
(
id
,
value
)
{
var
context
=
this
;
return
waitForOpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
put
({
"
id
"
:
id
,
"
doc
"
:
filterDocValues
(
value
,
context
.
_index_keys
)
}));
});
});
};
IndexStorage2
.
prototype
.
put
=
function
(
id
,
value
)
{
var
context
=
this
;
return
context
.
_sub_storage
.
put
(
id
,
value
)
.
push
(
function
()
{
return
waitForUpdatedOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
put
({
"
id
"
:
id
,
"
doc
"
:
filterDocValues
(
value
,
context
.
_index_keys
)
}));
});
});
return
context
.
_put
(
id
,
value
);
});
};
...
...
@@ -449,19 +411,7 @@
var
context
=
this
;
return
context
.
_sub_storage
.
post
(
value
)
.
push
(
function
(
id
)
{
return
waitForUpdatedOpenIndexedDB
(
context
.
_database_name
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
).
put
({
"
id
"
:
id
,
"
doc
"
:
filterDocValues
(
value
,
context
.
_index_keys
)
}))
.
then
(
function
()
{
return
id
;
});
});
});
context
.
_put
(
id
,
value
);
Romain Courteaud
@romain
·
Mar 21, 2019
@preet
do not forget
return
@preet do not forget `return`
Please
register
or
sign in
to reply
});
};
...
...
@@ -469,7 +419,7 @@
var
context
=
this
;
return
context
.
_sub_storage
.
remove
(
id
)
.
push
(
function
()
{
return
waitFor
UpdatedOpenIndexedDB
(
context
.
_database_name
,
return
waitFor
OpenIndexedDB
(
context
.
_database_name
,
context
.
_version
,
context
.
_index_keys
,
function
(
db
)
{
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readwrite
"
,
function
(
tx
)
{
...
...
test/jio.storage/indexstorage2.tests.js
View file @
0cbb66e4
...
...
@@ -1112,6 +1112,7 @@
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
version
:
1
,
index_keys
:
[
"
a
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
...
...
@@ -1143,6 +1144,7 @@
context
.
jio
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
version
:
2
,
index_keys
:
[
"
a
"
,
"
b
"
,
"
c
"
],
sub_storage
:
{
type
:
"
dummystorage3
"
...
...
@@ -1179,6 +1181,7 @@
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
[
"
a
"
,
"
c
"
],
version
:
3
,
sub_storage
:
{
type
:
"
dummystorage3
"
}
...
...
@@ -1214,6 +1217,63 @@
});
});
test
(
"
Parallel test
"
,
function
()
{
var
context
=
this
,
i
,
promise_list
=
[],
jio_list
=
[],
index_keys_combinations
;
stop
();
expect
(
1
);
DummyStorage3
.
prototype
.
put
=
function
(
id
)
{
return
id
;
};
DummyStorage3
.
prototype
.
hasCapacity
=
function
()
{
return
false
;
};
function
random
(
limit
)
{
return
Math
.
floor
(
Math
.
random
()
*
Math
.
floor
(
limit
));
}
index_keys_combinations
=
[[],
[
'
a
'
],
[
'
b
'
],
[
'
c
'
],
[
'
d
'
],
[
'
e
'
],
[
'
a
'
,
'
b
'
],
[
'
a
'
,
'
c
'
],
[
'
a
'
,
'
d
'
],
[
'
a
'
,
'
e
'
],
[
'
b
'
,
'
c
'
],
[
'
b
'
,
'
d
'
],
[
'
b
'
,
'
e
'
],
[
'
c
'
,
'
d
'
],
[
'
c
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
],
[
'
b
'
,
'
c
'
,
'
d
'
],
[
'
c
'
,
'
d
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
],
[
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
],
[
'
a
'
,
'
b
'
,
'
c
'
,
'
d
'
,
'
e
'
]];
for
(
i
=
0
;
i
<
100
;
i
+=
1
)
{
jio_list
[
i
]
=
jIO
.
createJIO
({
type
:
"
index2
"
,
database
:
"
index2_test
"
,
index_keys
:
index_keys_combinations
[
random
(
index_keys_combinations
.
length
-
1
)],
version
:
i
+
1
,
sub_storage
:
{
type
:
"
dummystorage3
"
}
});
}
for
(
i
=
0
;
i
<
100
;
i
+=
1
)
{
promise_list
.
push
(
jio_list
[
i
].
put
(
"
43
"
,
{
"
a
"
:
"
obscure
"
,
"
b
"
:
"
cr
"
,
"
c
"
:
"
34
"
,
"
d
"
:
"
5454
"
,
"
e
"
:
34
}));
}
RSVP
.
all
(
promise_list
)
.
then
(
function
()
{
return
jio_list
[
99
].
allDocs
();
})
.
then
(
function
(
result
)
{
context
.
jio
=
jio_list
[
99
];
equal
(
result
.
data
.
total_rows
,
1
);
})
.
fail
(
function
(
error
)
{
console
.
log
(
error
);
})
.
always
(
function
()
{
start
();
});
});
/////////////////////////////////////////////////////////////////
// IndexStorage2.getAttachment
/////////////////////////////////////////////////////////////////
...
...
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