You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-07-16 00:14:34 +02:00
Tools: Added testing command to create many items in parallel
This commit is contained in:
@ -3,6 +3,8 @@ import { reg } from '@joplin/lib/registry';
|
|||||||
import Note from '@joplin/lib/models/Note';
|
import Note from '@joplin/lib/models/Note';
|
||||||
import uuid from '@joplin/lib/uuid';
|
import uuid from '@joplin/lib/uuid';
|
||||||
import populateDatabase from '@joplin/lib/services/debug/populateDatabase';
|
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 {
|
function randomElement(array: any[]): any {
|
||||||
if (!array.length) return null;
|
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);
|
await Promise.all(promises);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user