Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,19 +41,21 @@
]
},
"devDependencies": {
"@babel/cli": "^7.4.3",
"@babel/core": "^7.4.3",
"@babel/preset-env": "^7.4.3",
"babel-jest": "^24.7.1",
"jest": "^24.7.1",
"rollup": "^1.10.0",
"rollup-plugin-babel": "^4.3.2",
"rollup-plugin-node-resolve": "^4.2.3",
"rollup-plugin-terser": "^4.0.4"
"@babel/cli": "^7.8.4",
"@babel/core": "^7.9.0",
"@babel/preset-env": "^7.9.5",
"babel-jest": "^25.3.0",
"jest": "^25.3.0",
"rollup": "^2.6.1",
"rollup-plugin-babel": "^4.4.0",
"rollup-plugin-commonjs": "^10.1.0",
"rollup-plugin-node-resolve": "^5.2.0",
"rollup-plugin-terser": "^5.3.0"
},
"dependencies": {
"opencollective": "^1.0.3",
"opencollective-postinstall": "^2.0.2",
"opencollective": "^1.0.3"
"p-limit": "^2.3.0"
},
"collective": {
"type": "opencollective",
Expand Down
4 changes: 4 additions & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import resolve from 'rollup-plugin-node-resolve';
import babel from 'rollup-plugin-babel';
import { terser } from 'rollup-plugin-terser';
import commonjs from 'rollup-plugin-commonjs';

const env = process.env.NODE_ENV;
const config = {
Expand Down Expand Up @@ -31,6 +32,9 @@ const config = {
exclude: 'node_modules/**',
}),
terser(),
commonjs({
include: 'node_modules/**'
})
],
};

Expand Down
10 changes: 6 additions & 4 deletions src/storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* sunnylqm
*/
import { NotFoundError, ExpiredError } from './error';
import PLimit from 'p-limit'

export { NotFoundError, ExpiredError };

Expand All @@ -15,6 +16,7 @@ export default class Storage {
this._s = options.storageBackend || null;
this._innerVersion = 11;
this.cache = {};
this.limiter = PLimit(options.concurrency > 0 ? options.concurrency : 300)

if (this._s && this._s.setItem) {
try {
Expand Down Expand Up @@ -148,18 +150,18 @@ export default class Storage {
}
}
getBatchData(querys) {
return Promise.all(querys.map(query => this.load(query)));
return Promise.all(querys.map(query => this.limiter(() => this.load(query))));
}
async getBatchDataWithIds(params) {
let { key, ids, syncInBackground, syncParams } = params;
const tasks = ids.map(id =>
const tasks = ids.map(id => this.limiter(() =>
this.load({
key,
id,
syncInBackground,
autoSync: false,
batched: true,
}),
})),
);
const results = await Promise.all(tasks);
const missingIds = [];
Expand Down Expand Up @@ -341,7 +343,7 @@ export default class Storage {
}
clearMapForKey(key) {
return this._mapPromise.then(() => {
let tasks = (this._m.__keys__[key] || []).map(id => this.remove({ key, id }));
let tasks = (this._m.__keys__[key] || []).map(id => this.limiter(() => this.remove({ key, id })));
return Promise.all(tasks);
});
}
Expand Down
Loading