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
Boris Kocherov
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
Show 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 @@
...
@@ -144,41 +144,63 @@
// remove them later if they were not required.
// remove them later if they were not required.
include_docs
=
(
options
.
include_docs
||
options
.
query
)
?
true
:
false
;
include_docs
=
(
options
.
include_docs
||
options
.
query
)
?
true
:
false
;
substorage
.
allDocs
({
include_docs
:
include_docs
}).
substorage
.
allDocs
({
then
(
function
(
response
)
{
"
include_docs
"
:
include_docs
}).
then
(
function
(
response
)
{
if
(
options
.
query
)
{
var
data_rows
=
response
.
data
.
rows
,
docs
=
{},
row
,
i
,
l
;
var
docs
=
response
.
data
.
rows
.
map
(
function
(
row
)
{
return
row
.
doc
;
}),
rows_map
=
{};
// build a mapping to avoid slowness
if
(
!
include_docs
)
{
response
.
data
.
rows
.
forEach
(
function
(
row
)
{
return
response
;
rows_map
[
row
.
id
]
=
row
;
}
});
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
;
}
}
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
,
return
jIO
.
QueryFactory
.
create
(
options
.
query
||
""
,
that
.
_key_schema
).
that
.
_key_schema
).
exec
(
data_rows
,
options
).
exec
(
docs
,
options
).
then
(
function
(
filtered_docs
)
{
then
(
function
(
filtered_docs
)
{
// reconstruct filtered rows, preserving the order from docs
// reconstruct filtered rows, preserving the order from docs
var
rows
=
filtered_docs
.
map
(
function
(
doc
)
{
if
(
options
.
include_docs
)
{
var
row
=
rows_map
[
doc
.
_id
];
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
// remove docs if not needed in the original call
filtered_docs
[
i
]
=
{
if
(
!
options
.
include_docs
)
{
"
id
"
:
filtered_docs
[
i
].
_id
,
delete
row
.
doc
;
"
doc
"
:
docs
[
filtered_docs
[
i
].
_id
],
"
value
"
:
options
.
select_list
?
filtered_docs
[
i
]
:
{}
};
delete
filtered_docs
[
i
].
value
.
_id
;
}
}
return
row
;
}
else
{
});
for
(
i
=
0
,
l
=
filtered_docs
.
length
;
i
<
l
;
i
+=
1
)
{
response
.
data
.
rows
=
rows
;
filtered_docs
[
i
]
=
{
response
.
data
.
total_rows
=
rows
.
length
;
"
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
;
return
response
;
});
});
}
return
RSVP
.
resolve
(
response
);
}).
}).
then
(
command
.
success
,
command
.
error
,
command
.
notify
);
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