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
940f9c36
Commit
940f9c36
authored
Mar 25, 2019
by
preetwinder
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove unneeded parts
parent
854c1b59
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
59 additions
and
771 deletions
+59
-771
src/jio.storage/indexstorage2.js
src/jio.storage/indexstorage2.js
+26
-158
test/jio.storage/indexstorage2.tests.js
test/jio.storage/indexstorage2.tests.js
+33
-613
No files found.
src/jio.storage/indexstorage2.js
View file @
940f9c36
...
...
@@ -41,72 +41,9 @@
this
.
_version
=
description
.
version
||
undefined
;
}
function
convertToObject
(
list
,
key
)
{
var
i
,
obj
=
{};
for
(
i
=
0
;
i
<
list
.
length
;
i
+=
1
)
{
obj
[
list
[
i
][
key
]]
=
list
[
i
];
}
return
obj
;
}
function
keyCount
(
obj
)
{
return
Object
.
keys
(
obj
).
length
;
}
function
union
(
list
)
{
var
result
,
i
,
j
;
if
(
list
.
length
===
0
)
{
return
[];
}
result
=
convertToObject
(
list
[
0
],
'
id
'
);
for
(
i
=
1
;
i
<
list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
list
[
i
].
length
;
j
+=
1
)
{
if
(
result
[
list
[
i
][
j
].
id
])
{
if
(
keyCount
(
result
[
list
[
i
][
j
].
id
].
doc
)
<
keyCount
(
list
[
i
][
j
].
doc
))
{
result
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
}
else
{
result
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
}
}
return
Object
.
values
(
result
);
}
function
intersect
(
list
)
{
var
result
,
temp
=
{},
i
,
j
;
if
(
list
.
length
===
0
)
{
return
[];
}
result
=
convertToObject
(
list
[
0
],
'
id
'
);
for
(
i
=
1
;
i
<
list
.
length
;
i
+=
1
)
{
for
(
j
=
0
;
j
<
list
[
i
].
length
;
j
+=
1
)
{
if
(
result
[
list
[
i
][
j
].
id
])
{
if
(
keyCount
(
result
[
list
[
i
][
j
].
id
].
doc
)
<
keyCount
(
list
[
i
][
j
].
doc
))
{
temp
[
list
[
i
][
j
].
id
]
=
list
[
i
][
j
];
}
else
{
temp
[
list
[
i
][
j
].
id
]
=
result
[
list
[
i
][
j
].
id
];
}
}
}
result
=
temp
;
temp
=
{};
}
return
Object
.
values
(
result
);
}
IndexStorage2
.
prototype
.
hasCapacity
=
function
(
name
)
{
var
this_storage_capacity_list
=
[
"
select
"
,
"
list
"
,
"
query
"
,
"
sort
"
,
"
include
"
];
if
(
this_storage_capacity_list
.
indexOf
(
name
)
!==
-
1
)
{
return
true
;
}
return
(
name
===
'
query
'
)
||
(
name
===
'
limit
'
)
||
(
name
===
'
list
'
)
||
this
.
_sub_storage
.
hasCapacity
(
name
);
};
function
handleUpgradeNeeded
(
evt
,
index_keys
)
{
...
...
@@ -173,11 +110,10 @@
reject
(
"
Connection to:
"
+
db_name
+
"
timeout
"
);
};
// request.onblocked = function (evt) {
// console.log("evt", evt);
// request.result.close();
// reject("Connection to: " + db_name + " was blocked");
// };
request
.
onblocked
=
function
()
{
request
.
result
.
close
();
reject
(
"
Connection to:
"
+
db_name
+
"
was blocked
"
);
};
// Create DB if necessary //
request
.
onupgradeneeded
=
function
(
evt
)
{
...
...
@@ -264,33 +200,7 @@
return
doc
;
}
IndexStorage2
.
prototype
.
forceIncludeDocs
=
function
(
result
)
{
var
i
,
get_list
=
{},
context
=
this
;
return
RSVP
.
Queue
()
.
push
(
function
()
{
for
(
i
=
0
;
i
<
result
.
length
;
i
+=
1
)
{
if
(
!
(
result
[
i
].
include
))
{
get_list
[
result
[
i
].
id
]
=
context
.
_sub_storage
.
get
(
result
[
i
].
id
);
}
}
return
RSVP
.
hash
(
get_list
);
})
.
push
(
function
(
get_result
)
{
var
keys
;
result
=
convertToObject
(
result
,
'
id
'
);
keys
=
Object
.
keys
(
get_result
);
for
(
i
=
0
;
i
<
keys
.
length
;
i
+=
1
)
{
result
[
keys
[
i
]].
doc
=
get_result
[
keys
[
i
]];
}
result
=
Object
.
values
(
result
);
return
result
;
})
.
push
(
function
()
{
return
result
;
});
};
IndexStorage2
.
prototype
.
_runQuery
=
function
(
index
,
value
)
{
IndexStorage2
.
prototype
.
_runQuery
=
function
(
key
,
value
,
limit
)
{
var
context
=
this
;
return
new
RSVP
.
Queue
()
.
push
(
function
()
{
...
...
@@ -299,7 +209,7 @@
return
waitForTransaction
(
db
,
[
"
index-store
"
],
"
readonly
"
,
function
(
tx
)
{
return
waitForIDBRequest
(
tx
.
objectStore
(
"
index-store
"
)
.
index
(
"
Index-
"
+
index
).
getAll
(
value
))
.
index
(
"
Index-
"
+
key
).
getAll
(
value
,
limit
))
.
then
(
function
(
evt
)
{
return
evt
.
target
.
result
;
});
...
...
@@ -308,70 +218,28 @@
});
};
IndexStorage2
.
prototype
.
_processQueryObject
=
function
(
object
,
include_docs
)
{
var
promise_list
=
[],
context
=
this
,
i
;
include_docs
=
include_docs
||
false
;
return
RSVP
.
Queue
()
.
push
(
function
()
{
if
(
object
.
type
===
"
simple
"
)
{
if
((
context
.
_index_keys
.
indexOf
(
object
.
key
)
===
-
1
))
{
return
context
.
_sub_storage
.
allDocs
({
"
query
"
:
object
.
key
+
"
:
"
+
object
.
value
,
"
include_docs
"
:
include_docs
})
.
push
(
function
(
result
)
{
if
(
include_docs
)
{
result
.
data
.
rows
.
map
(
function
(
v
)
{
v
.
include
=
true
;
});
}
return
result
.
data
.
rows
;
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
var
context
=
this
,
query
;
if
(
options
.
query
)
{
query
=
parseStringToObject
(
options
.
query
);
if
(
query
.
type
===
'
simple
'
)
{
if
(
context
.
_index_keys
.
indexOf
(
query
.
key
)
!==
-
1
)
{
return
context
.
_runQuery
(
query
.
key
,
query
.
value
,
options
.
limit
)
.
push
(
function
(
result
)
{
return
result
.
map
(
function
(
value
)
{
return
{
id
:
value
.
id
,
value
:
{}
};
});
}
return
context
.
_runQuery
(
object
.
key
,
object
.
value
);
}
if
(
object
.
type
===
"
complex
"
)
{
for
(
i
=
0
;
i
<
object
.
query_list
.
length
;
i
+=
1
)
{
promise_list
.
push
(
context
.
_processQueryObject
(
object
.
query_list
[
i
],
include_docs
));
}
return
RSVP
.
all
(
promise_list
)
.
then
(
function
(
result
)
{
if
(
object
.
operator
===
"
OR
"
)
{
return
union
(
result
);
}
if
(
object
.
operator
===
"
AND
"
)
{
return
intersect
(
result
);
}
});
}
})
};
IndexStorage2
.
prototype
.
buildQuery
=
function
(
options
)
{
var
context
=
this
;
if
(
options
.
query
)
{
return
this
.
_processQueryObject
(
parseStringToObject
(
options
.
query
),
options
.
include_docs
)
.
push
(
function
(
result
)
{
if
(
options
.
include_docs
)
{
result
=
context
.
forceIncludeDocs
(
result
);
options
.
select_list
=
undefined
;
}
else
{
options
.
select_list
=
options
.
select_list
||
[];
}
return
result
;
})
.
push
(
function
(
result
)
{
return
result
.
map
(
function
(
value
)
{
return
{
"
id
"
:
value
.
id
,
"
value
"
:
filterDocValues
(
value
.
doc
,
options
.
select_list
)
};
});
});
}
}
return
context
.
_sub_storage
.
allDocs
(
options
)
.
push
(
function
(
result
)
{
return
result
.
data
.
rows
;
});
};
IndexStorage2
.
prototype
.
get
=
function
()
{
...
...
test/jio.storage/indexstorage2.tests.js
View file @
940f9c36
This diff is collapsed.
Click to expand it.
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