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
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Aurel
jio
Commits
6dbd0d97
Commit
6dbd0d97
authored
Mar 26, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve querystorage allDocs speed
parent
52472bef
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
34 deletions
+56
-34
src/jio.storage/querystorage.js
src/jio.storage/querystorage.js
+56
-34
No files found.
src/jio.storage/querystorage.js
View file @
6dbd0d97
...
...
@@ -144,41 +144,63 @@
// remove them later if they were not required.
include_docs
=
(
options
.
include_docs
||
options
.
query
)
?
true
:
false
;
substorage
.
allDocs
({
include_docs
:
include_docs
}).
then
(
function
(
response
)
{
if
(
options
.
query
)
{
var
docs
=
response
.
data
.
rows
.
map
(
function
(
row
)
{
return
row
.
doc
;
}),
rows_map
=
{};
// build a mapping to avoid slowness
response
.
data
.
rows
.
forEach
(
function
(
row
)
{
rows_map
[
row
.
id
]
=
row
;
});
return
jIO
.
QueryFactory
.
create
(
options
.
query
,
that
.
_key_schema
).
exec
(
docs
,
options
).
then
(
function
(
filtered_docs
)
{
// reconstruct filtered rows, preserving the order from docs
var
rows
=
filtered_docs
.
map
(
function
(
doc
)
{
var
row
=
rows_map
[
doc
.
_id
];
// remove docs if not needed in the original call
if
(
!
options
.
include_docs
)
{
delete
row
.
doc
;
}
return
row
;
});
response
.
data
.
rows
=
rows
;
response
.
data
.
total_rows
=
rows
.
length
;
return
response
;
});
substorage
.
allDocs
({
"
include_docs
"
:
include_docs
}).
then
(
function
(
response
)
{
var
data_rows
=
response
.
data
.
rows
,
docs
=
{},
row
,
i
,
l
;
if
(
!
include_docs
)
{
return
response
;
}
if
(
options
.
include_docs
)
{
for
(
i
=
0
,
l
=
data_rows
.
length
;
i
<
l
;
i
+=
1
)
{
row
=
data_rows
[
i
];
docs
[
row
.
id
]
=
JSON
.
parse
(
JSON
.
stringify
(
row
.
doc
));
row
.
doc
.
_id
=
row
.
id
;
data_rows
[
i
]
=
row
.
doc
;
}
return
RSVP
.
resolve
(
response
);
}).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
}
else
{
for
(
i
=
0
,
l
=
data_rows
.
length
;
i
<
l
;
i
+=
1
)
{
row
=
data_rows
[
i
];
row
.
doc
.
_id
=
row
.
id
;
data_rows
[
i
]
=
row
.
doc
;
}
}
if
(
options
.
select_list
)
{
options
.
select_list
.
push
(
"
_id
"
);
}
return
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
that
.
_key_schema
).
exec
(
data_rows
,
options
).
then
(
function
(
filtered_docs
)
{
// reconstruct filtered rows, preserving the order from docs
if
(
options
.
include_docs
)
{
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
filtered_docs
[
i
]
=
{
"
id
"
:
filtered_docs
[
i
].
_id
,
"
doc
"
:
docs
[
filtered_docs
[
i
].
_id
],
"
value
"
:
options
.
select_list
?
filtered_docs
[
i
]
:
{}
};
delete
filtered_docs
[
i
].
value
.
_id
;
}
}
else
{
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
filtered_docs
[
i
]
=
{
"
id
"
:
filtered_docs
[
i
].
_id
,
"
value
"
:
options
.
select_list
?
filtered_docs
[
i
]
:
{}
};
delete
filtered_docs
[
i
].
value
.
_id
;
}
}
response
.
data
.
rows
=
filtered_docs
;
response
.
data
.
total_rows
=
filtered_docs
.
length
;
return
response
;
});
}).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
};
...
...
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