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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Xiaowu Zhang
jio
Commits
4ead8961
Commit
4ead8961
authored
May 02, 2014
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
gidstorage alldocs handles limit option
parent
83b0c1f2
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
117 additions
and
31 deletions
+117
-31
src/jio.storage/gidstorage.js
src/jio.storage/gidstorage.js
+117
-31
No files found.
src/jio.storage/gidstorage.js
View file @
4ead8961
...
@@ -17,7 +17,7 @@
...
@@ -17,7 +17,7 @@
*/
*/
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*jslint indent: 2, maxlen: 80, sloppy: true, nomen: true */
/*global define, jIO */
/*global define, jIO
, RSVP
*/
/**
/**
* JIO GID Storage. Type = 'gid'.
* JIO GID Storage. Type = 'gid'.
...
@@ -51,8 +51,8 @@
...
@@ -51,8 +51,8 @@
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
if
(
typeof
define
===
'
function
'
&&
define
.
amd
)
{
return
define
(
dependencies
,
module
);
return
define
(
dependencies
,
module
);
}
}
module
(
jIO
);
module
(
jIO
,
RSVP
);
}([
'
jio
'
],
function
(
jIO
)
{
}([
'
jio
'
,
'
rsvp
'
],
function
(
jIO
,
RSVP
)
{
"
use strict
"
;
"
use strict
"
;
var
dcmi_types
,
metadata_actions
,
content_type_re
,
tool
;
var
dcmi_types
,
metadata_actions
,
content_type_re
,
tool
;
...
@@ -273,6 +273,56 @@
...
@@ -273,6 +273,56 @@
return
object
;
return
object
;
}
}
function
doWhile
(
callback
)
{
var
cancelled
,
p1
=
RSVP
.
resolve
(),
p2
;
return
new
RSVP
.
Promise
(
function
(
done
,
fail
,
notify
)
{
function
next
(
value
)
{
if
(
value
)
{
try
{
value
=
callback
();
}
catch
(
e
)
{
return
fail
(
e
);
}
if
(
cancelled
)
{
return
;
}
if
(
value
&&
typeof
value
.
then
===
"
function
"
)
{
p1
=
value
;
p2
=
value
.
then
(
next
,
fail
,
notify
);
}
else
{
p2
=
p2
.
then
(
next
.
bind
(
null
,
value
),
fail
,
notify
);
}
return
;
}
done
();
}
p2
=
p1
.
then
(
next
.
bind
(
null
,
true
));
},
function
()
{
cancelled
=
true
;
if
(
typeof
p1
.
cancel
===
"
function
"
)
{
p1
.
cancel
();
}
if
(
typeof
p2
.
cancel
===
"
function
"
)
{
p2
.
cancel
();
}
});
}
function
arrayExtend
(
aThis
)
{
/*jslint plusplus: true */
var
nArgIndex
,
nArgLength
,
value
,
nValueIndex
,
nValueLength
,
nThisLength
;
nThisLength
=
aThis
.
length
;
for
(
nArgIndex
=
1
,
nArgLength
=
arguments
.
length
;
nArgIndex
<
nArgLength
;
nArgIndex
+=
1
)
{
value
=
arguments
[
nArgIndex
];
if
(
Array
.
isArray
(
value
))
{
for
(
nValueIndex
=
0
,
nValueLength
=
value
.
length
;
nValueIndex
<
nValueLength
;
nValueIndex
+=
1
)
{
aThis
[
nThisLength
++
]
=
value
[
nValueIndex
];
}
}
else
{
aThis
[
nThisLength
++
]
=
value
;
}
}
return
aThis
;
}
/**
/**
* The gid storage used by JIO.
* The gid storage used by JIO.
*
*
...
@@ -550,10 +600,31 @@
...
@@ -550,10 +600,31 @@
*/
*/
that
.
allDocs
=
function
(
command
,
param
,
options
)
{
that
.
allDocs
=
function
(
command
,
param
,
options
)
{
/*jslint unparam: true */
/*jslint unparam: true */
var
include_docs
;
var
include_docs
,
limit_start
,
limit_length
,
rows
,
i
=
0
;
include_docs
=
options
.
include_docs
;
include_docs
=
options
.
include_docs
;
options
.
include_docs
=
true
;
options
.
include_docs
=
true
;
command
.
storage
(
priv
.
sub_storage
).
allDocs
(
if
(
Array
.
isArray
(
options
.
limit
))
{
if
(
options
.
limit
.
length
>
1
)
{
limit_start
=
options
.
limit
[
0
];
limit_length
=
options
.
limit
[
1
];
}
else
{
limit_start
=
0
;
limit_length
=
options
.
limit
[
0
];
}
}
else
if
(
typeof
options
.
limit
===
"
number
"
)
{
limit_start
=
0
;
limit_length
=
options
.
limit
;
}
function
doAllDocs
(
i
)
{
if
(
limit_length
)
{
options
.
limit
=
[
limit_start
+
(
limit_length
*
i
),
limit_length
];
}
return
command
.
storage
(
priv
.
sub_storage
).
allDocs
(
options
options
).
then
(
function
(
response
)
{
).
then
(
function
(
response
)
{
/*jslint ass: true */
/*jslint ass: true */
...
@@ -575,16 +646,31 @@
...
@@ -575,16 +646,31 @@
}
}
}
}
}
}
doc_gids
=
undefined
;
// free memory
if
(
rows
)
{
row
=
undefined
;
arrayExtend
(
rows
,
result
);
}
else
{
rows
=
result
;
}
});
}
doWhile
(
function
()
{
/*jslint plusplus: true */
return
doAllDocs
(
i
++
).
then
(
function
()
{
if
(
limit_length
)
{
if
(
rows
.
length
<
limit_length
)
{
return
true
;
}
rows
.
length
=
limit_length
;
}
return
false
;
});
}).
then
(
function
()
{
command
.
success
({
"
data
"
:
{
command
.
success
({
"
data
"
:
{
"
total_rows
"
:
r
esult
.
length
,
"
total_rows
"
:
r
ows
.
length
,
"
rows
"
:
r
esult
"
rows
"
:
r
ows
}});
}});
},
function
(
err
)
{
},
command
.
error
);
err
.
message
=
"
Cannot get all documents
"
;
return
command
.
error
(
err
);
});
};
};
...
...
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