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
Tomáš Peterka
jio
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
Hide 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 @@
...
@@ -2,7 +2,7 @@
/*global parseStringToObject: true, emptyFunction: true, sortOn: true, limit:
/*global parseStringToObject: true, emptyFunction: true, sortOn: true, limit:
true, select: true, exports, stringEscapeRegexpCharacters: true,
true, select: true, exports, stringEscapeRegexpCharacters: true,
deepClone, RSVP, sequence, background, jIO, metadataValueToStringArray,
deepClone, RSVP, sequence, background, jIO, metadataValueToStringArray,
sortFunction */
sortFunction
, setTimeout, clearTimeout
*/
/**
/**
* The query to use to filter a list of objects.
* The query to use to filter a list of objects.
...
@@ -68,11 +68,9 @@ Query.prototype.exec = function (item_list, option) {
...
@@ -68,11 +68,9 @@ Query.prototype.exec = function (item_list, option) {
background
.
removeUnmatchedSortLimitAndSelect
=
function
(
event
)
{
background
.
removeUnmatchedSortLimitAndSelect
=
function
(
event
)
{
var
j
,
task
=
event
.
data
.
option
,
array
=
event
.
data
.
item_list
;
var
j
,
task
=
event
.
data
.
option
,
array
=
event
.
data
.
item_list
;
// remove unmatched documents
// remove unmatched documents
if
(
task
.
match_list
)
{
for
(
j
=
array
.
length
-
1
;
j
>=
0
;
j
-=
1
)
{
for
(
j
=
task
.
match_list
.
length
-
1
;
j
>=
0
;
j
-=
1
)
{
if
(
!
array
[
j
])
{
if
(
!
task
.
match_list
[
j
])
{
array
.
splice
(
j
,
1
);
array
.
splice
(
j
,
1
);
}
}
}
}
}
// sort documents
// sort documents
...
@@ -97,7 +95,6 @@ Query.prototype.exec = function (item_list, option) {
...
@@ -97,7 +95,6 @@ Query.prototype.exec = function (item_list, option) {
"
onmessage =
"
+
background
.
removeUnmatchedSortLimitAndSelect
.
toString
()
"
onmessage =
"
+
background
.
removeUnmatchedSortLimitAndSelect
.
toString
()
);
);
}
}
var
i
,
promises
=
[];
if
(
!
Array
.
isArray
(
item_list
))
{
if
(
!
Array
.
isArray
(
item_list
))
{
throw
new
TypeError
(
"
Query().exec(): Argument 1 is not of type 'array'
"
);
throw
new
TypeError
(
"
Query().exec(): Argument 1 is not of type 'array'
"
);
}
}
...
@@ -108,18 +105,54 @@ Query.prototype.exec = function (item_list, option) {
...
@@ -108,18 +105,54 @@ Query.prototype.exec = function (item_list, option) {
throw
new
TypeError
(
"
Query().exec():
"
+
throw
new
TypeError
(
"
Query().exec():
"
+
"
Optional argument 2 is not of type 'object'
"
);
"
Optional argument 2 is not of type 'object'
"
);
}
}
for
(
i
=
0
;
i
<
item_list
.
length
;
i
+=
1
)
{
function
sleep
(
delay
,
value
)
{
if
(
!
item_list
[
i
])
{
var
ident
;
promises
.
push
(
RSVP
.
resolve
(
false
));
return
new
RSVP
.
Promise
(
function
(
done
)
{
}
else
{
ident
=
setTimeout
(
done
,
delay
,
value
);
promises
.
push
(
this
.
match
(
item_list
[
i
]));
},
function
()
{
}
clearTimeout
(
ident
);
});
}
}
var
this_
=
this
;
return
sequence
([
function
()
{
return
sequence
([
function
()
{
return
RSVP
.
all
(
promises
);
// sequential operation
},
function
(
answers
)
{
var
begin
=
Date
.
now
();
return
jIO
.
util
.
forEach
(
item_list
,
function
(
value
,
i
)
{
if
(
value
)
{
return
sequence
([
function
()
{
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
=
{
option
=
{
"
match_list
"
:
answers
,
"
limit
"
:
option
.
limit
,
"
limit
"
:
option
.
limit
,
"
sort_on
"
:
option
.
sort_on
,
"
sort_on
"
:
option
.
sort_on
,
"
select_list
"
:
option
.
select_list
"
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