Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
jio_mebibou
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
Alexandra Rogova
jio_mebibou
Commits
84107abc
Commit
84107abc
authored
Apr 22, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
query parse documents sequentially
Waits 4 ms every 50 ms.
parent
b9ed2084
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
16 deletions
+49
-16
src/queries/core/query.js
src/queries/core/query.js
+49
-16
No files found.
src/queries/core/query.js
View file @
84107abc
...
...
@@ -2,7 +2,7 @@
/*global parseStringToObject: true, emptyFunction: true, sortOn: true, limit:
true, select: true, exports, stringEscapeRegexpCharacters: true,
deepClone, RSVP, sequence, background, jIO, metadataValueToStringArray,
sortFunction */
sortFunction
, setTimeout, clearTimeout
*/
/**
* The query to use to filter a list of objects.
...
...
@@ -68,13 +68,11 @@ Query.prototype.exec = function (item_list, option) {
background
.
removeUnmatchedSortLimitAndSelect
=
function
(
event
)
{
var
j
,
task
=
event
.
data
.
option
,
array
=
event
.
data
.
item_list
;
// remove unmatched documents
if
(
task
.
match_list
)
{
for
(
j
=
task
.
match_list
.
length
-
1
;
j
>=
0
;
j
-=
1
)
{
if
(
!
task
.
match_list
[
j
])
{
for
(
j
=
array
.
length
-
1
;
j
>=
0
;
j
-=
1
)
{
if
(
!
array
[
j
])
{
array
.
splice
(
j
,
1
);
}
}
}
// sort documents
if
(
task
.
sort_on
)
{
sortOn
(
task
.
sort_on
,
array
);
...
...
@@ -97,7 +95,6 @@ Query.prototype.exec = function (item_list, option) {
"
onmessage =
"
+
background
.
removeUnmatchedSortLimitAndSelect
.
toString
()
);
}
var
i
,
promises
=
[];
if
(
!
Array
.
isArray
(
item_list
))
{
throw
new
TypeError
(
"
Query().exec(): Argument 1 is not of type 'array'
"
);
}
...
...
@@ -108,18 +105,54 @@ Query.prototype.exec = function (item_list, option) {
throw
new
TypeError
(
"
Query().exec():
"
+
"
Optional argument 2 is not of type 'object'
"
);
}
for
(
i
=
0
;
i
<
item_list
.
length
;
i
+=
1
)
{
if
(
!
item_list
[
i
])
{
promises
.
push
(
RSVP
.
resolve
(
false
));
}
else
{
promises
.
push
(
this
.
match
(
item_list
[
i
]));
}
function
sleep
(
delay
,
value
)
{
var
ident
;
return
new
RSVP
.
Promise
(
function
(
done
)
{
ident
=
setTimeout
(
done
,
delay
,
value
);
},
function
()
{
clearTimeout
(
ident
);
});
}
var
this_
=
this
;
return
sequence
([
function
()
{
// sequential operation
var
begin
=
Date
.
now
();
return
jIO
.
util
.
forEach
(
item_list
,
function
(
value
,
i
)
{
if
(
value
)
{
return
sequence
([
function
()
{
return
RSVP
.
all
(
promises
);
},
function
(
answers
)
{
return
this_
.
match
(
item_list
[
i
]);
},
function
(
answer
)
{
if
(
!
answer
)
{
item_list
[
i
]
=
false
;
}
var
now
=
Date
.
now
();
if
(
begin
<=
now
-
50
)
{
begin
=
now
;
return
sleep
(
4
);
}
}]);
}
item_list
[
i
]
=
false
;
});
// // parallel operation
// var i, promises = [];
// function setToFalseIfNotMatch(i) {
// return function (a) {
// if (!a) {
// item_list[i] = false;
// }
// };
// }
// for (i = 0; i < item_list.length; i += 1) {
// if (!item_list[i]) {
// promises.push(RSVP.resolve(false));
// } else {
// promises.push(this_.match(item_list[i]).then(setToFalseIfNotMatch(i)));
// }
// }
// return RSVP.all(promises);
},
function
()
{
option
=
{
"
match_list
"
:
answers
,
"
limit
"
:
option
.
limit
,
"
sort_on
"
:
option
.
sort_on
,
"
select_list
"
:
option
.
select_list
...
...
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