appwrite-utils-cli 0.0.24 → 0.0.241

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -22,30 +22,34 @@ export class UsersController {
22
22
  this.users = new Users(this.config.appwriteClient);
23
23
  }
24
24
  async wipeUsers() {
25
- const users = await this.users.list([Query.limit(25)]);
25
+ const users = await this.users.list([Query.limit(200)]);
26
26
  const allUsers = users.users;
27
27
  let lastDocumentId;
28
- if (users.users.length >= 25) {
28
+ if (users.users.length >= 200) {
29
29
  lastDocumentId = users.users[users.users.length - 1].$id;
30
30
  }
31
31
  while (lastDocumentId) {
32
32
  const moreUsers = await this.users.list([
33
- Query.limit(25),
33
+ Query.limit(200),
34
34
  Query.cursorAfter(lastDocumentId),
35
35
  ]);
36
36
  allUsers.push(...moreUsers.users);
37
- if (moreUsers.users.length < 25) {
37
+ if (moreUsers.users.length < 200) {
38
38
  break;
39
39
  }
40
40
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
41
41
  }
42
- console.log("Deleting all users");
42
+ console.log("Deleting all users...");
43
43
  const userPromises = [];
44
- for (const user of allUsers) {
45
- userPromises.push(this.users.delete(user.$id));
44
+ const allUsersBatched = splitIntoBatches(allUsers);
45
+ for (const userBatch of allUsersBatched) {
46
+ for (const user of userBatch) {
47
+ userPromises.push(this.users.delete(user.$id));
48
+ }
46
49
  }
47
50
  const batchedUserPromises = splitIntoBatches(userPromises);
48
51
  for (const batch of batchedUserPromises) {
52
+ console.log(`Deleting ${batch.length} users...`);
49
53
  await Promise.all(batch);
50
54
  }
51
55
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "appwrite-utils-cli",
3
3
  "description": "Appwrite Utility Functions to help with database management, data conversion, data import, migrations, and much more. Meant to be used as a CLI tool, I do not recommend installing this in frontend environments.",
4
- "version": "0.0.24",
4
+ "version": "0.0.241",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -30,30 +30,34 @@ export class UsersController {
30
30
  }
31
31
 
32
32
  async wipeUsers() {
33
- const users = await this.users.list([Query.limit(25)]);
33
+ const users = await this.users.list([Query.limit(200)]);
34
34
  const allUsers = users.users;
35
35
  let lastDocumentId: string | undefined;
36
- if (users.users.length >= 25) {
36
+ if (users.users.length >= 200) {
37
37
  lastDocumentId = users.users[users.users.length - 1].$id;
38
38
  }
39
39
  while (lastDocumentId) {
40
40
  const moreUsers = await this.users.list([
41
- Query.limit(25),
41
+ Query.limit(200),
42
42
  Query.cursorAfter(lastDocumentId),
43
43
  ]);
44
44
  allUsers.push(...moreUsers.users);
45
- if (moreUsers.users.length < 25) {
45
+ if (moreUsers.users.length < 200) {
46
46
  break;
47
47
  }
48
48
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
49
49
  }
50
- console.log("Deleting all users");
50
+ console.log("Deleting all users...");
51
51
  const userPromises: Promise<string>[] = [];
52
- for (const user of allUsers) {
53
- userPromises.push(this.users.delete(user.$id));
52
+ const allUsersBatched = splitIntoBatches(allUsers);
53
+ for (const userBatch of allUsersBatched) {
54
+ for (const user of userBatch) {
55
+ userPromises.push(this.users.delete(user.$id));
56
+ }
54
57
  }
55
58
  const batchedUserPromises = splitIntoBatches(userPromises);
56
59
  for (const batch of batchedUserPromises) {
60
+ console.log(`Deleting ${batch.length} users...`);
57
61
  await Promise.all(batch);
58
62
  }
59
63
  }