mirror of
https://github.com/laurent22/joplin.git
synced 2025-01-11 18:24:43 +02:00
Tools: Added testing command to create many items in parallel
This commit is contained in:
parent
ab8681267e
commit
22d472df5c
@ -3,6 +3,8 @@ import { reg } from '@joplin/lib/registry';
|
||||
import Note from '@joplin/lib/models/Note';
|
||||
import uuid from '@joplin/lib/uuid';
|
||||
import populateDatabase from '@joplin/lib/services/debug/populateDatabase';
|
||||
import { readCredentialFile } from '@joplin/lib/utils/credentialFiles';
|
||||
import JoplinServerApi from '@joplin/lib/JoplinServerApi';
|
||||
|
||||
function randomElement(array: any[]): any {
|
||||
if (!array.length) return null;
|
||||
@ -87,6 +89,38 @@ class Command extends BaseCommand {
|
||||
}
|
||||
}
|
||||
|
||||
if (command === 'joplinServerParallelItemUpdate') {
|
||||
const randomContent = () => {
|
||||
const charCount = Math.random() * 1000;
|
||||
return 'a'.repeat(charCount);
|
||||
};
|
||||
|
||||
const joplinServerAuth = JSON.parse(await readCredentialFile('joplin-server-test.json'));
|
||||
|
||||
const api = new JoplinServerApi({
|
||||
baseUrl: () => joplinServerAuth.baseUrl,
|
||||
userContentBaseUrl: () => joplinServerAuth.userContentBaseUrl,
|
||||
username: () => joplinServerAuth.email,
|
||||
password: () => joplinServerAuth.password,
|
||||
});
|
||||
|
||||
const apiPut = async () => {
|
||||
await api.exec('PUT', 'api/items/root:/testing:/content', {}, randomContent(), {
|
||||
'Content-Type': 'application/octet-stream',
|
||||
});
|
||||
};
|
||||
|
||||
await apiPut();
|
||||
|
||||
const promises = [];
|
||||
for (let i = 0; i < 100; i++) {
|
||||
promises.push(void apiPut());
|
||||
}
|
||||
await Promise.all(promises);
|
||||
|
||||
console.info(await api.exec('GET', 'api/items/root:/testing:'));
|
||||
}
|
||||
|
||||
await Promise.all(promises);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user