Permalink
Browse files

minor refactor. add concurrencyLimit.

  • Loading branch information...
1 parent c72ca11 commit 57caf94947ff71e602231e58fd71ce8a00bf3d5e @chjj committed Dec 13, 2012
Showing with 26 additions and 17 deletions.
  1. +26 −17 lib/charged.js
View
43 lib/charged.js
@@ -948,9 +948,9 @@ Charged.prototype.get = function(path, query, callback, format) {
if (query.max) {
var max = query.max
- , out = []
+ , concurrency = 1
, pending = 0
- , concurrency = 1;
+ , out = [];
delete query.max;
@@ -959,13 +959,21 @@ Charged.prototype.get = function(path, query, callback, format) {
delete query.concurrency;
}
- query.per_page = 200;
+ if (concurrency > Charged.concurrencyLimit) {
+ concurrency = Charged.concurrencyLimit;
+ }
+
+ if (concurrency <= 0) {
+ concurrency = 1;
+ }
+
query.page = 0;
+ query.per_page = max;
var cb = function(err) {
// If `out` is maxed, execute callback even
// if there are still requests pending.
- if (pending > 0 && out.length < max) {
+ if (pending && out.length < max) {
return;
}
@@ -1017,7 +1025,7 @@ Charged.prototype.get = function(path, query, callback, format) {
delete query._per_page;
}
- if (query && Object.keys(query).length) {
+ if (Object.keys(query).length) {
query = qs.stringify(query);
path += ~path.indexOf('?')
? '&' + query
@@ -1123,19 +1131,20 @@ Charged.prototype.signupPage = function(product) {
* null == undocumented/non-existent
*/
+Charged.concurrencyLimit = 10;
+
Charged.limits = {
- 'default': 200,
- 'subscription': 200,
- 'component': 200,
- 'customer': 50,
- 'statement_ids': 10000,
- 'statement': null,
- 'event': 200,
- 'coupon': null,
- 'transaction': 200,
- 'product_family': null,
- 'product': null,
- 'webhook': Infinity
+ 'subscription': 200, // Default: 20
+ 'component': null, // Default: ? - Does not accept per_page, (maybe) only page.
+ 'customer': 50, // Default: 50 - Does not accept per_page, only page.
+ 'statement_ids': Infinity, // Default: 10000
+ 'statement': null, // Default: ?
+ 'event': 200, // Default: 20
+ 'coupon': null, // Default: ?
+ 'transaction': 200, // Default: 20
+ 'product_family': null, // Default: ? - Does not accept per_page, or (maybe) page.
+ 'product': null, // Default: ? - Does not accept per_page, or (maybe) page.
+ 'webhook': Infinity // Default: 20
};
/**

0 comments on commit 57caf94

Please sign in to comment.