appwrite-utils-cli 0.0.22 → 0.0.23

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.
package/README.md CHANGED
@@ -81,6 +81,7 @@ This setup ensures that developers have robust tools at their fingertips to mana
81
81
 
82
82
  ### Changelog
83
83
 
84
+ - 0.0.23: Added batching to user deletion
84
85
  - 0.0.22: Converted all import processes except `postImportActions` and Relationship Resolution to the local data import, so it should be much faster.
85
86
  - 0.0.6: Added `setTargetFieldFromOtherCollectionDocumentsByMatchingField` for the below, but setting a different field than the field you matched. The names are long, but at least you know what's going on lmao.
86
87
  - 0.0.5: Added `setFieldFromOtherCollectionDocuments` to set an array of ID's for instance from another collection as a `postImportAction`
@@ -2,6 +2,7 @@ import { Databases, ID, Query, Users } from "node-appwrite";
2
2
  import { AuthUserSchema, } from "../schemas/authUser.js";
3
3
  import _ from "lodash";
4
4
  import { logger } from "./logging.js";
5
+ import { splitIntoBatches } from "./migrationHelper.js";
5
6
  export class UsersController {
6
7
  config;
7
8
  users;
@@ -39,8 +40,13 @@ export class UsersController {
39
40
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
40
41
  }
41
42
  console.log("Deleting all users");
43
+ const userPromises = [];
42
44
  for (const user of allUsers) {
43
- await this.users.delete(user.$id);
45
+ userPromises.push(this.users.delete(user.$id));
46
+ }
47
+ const batchedUserPromises = splitIntoBatches(userPromises);
48
+ for (const batch of batchedUserPromises) {
49
+ await Promise.all(batch);
44
50
  }
45
51
  }
46
52
  async getAllUsers() {
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.22",
4
+ "version": "0.0.23",
5
5
  "main": "src/main.ts",
6
6
  "type": "module",
7
7
  "repository": {
@@ -7,6 +7,7 @@ import {
7
7
  } from "../schemas/authUser.js";
8
8
  import _ from "lodash";
9
9
  import { logger } from "./logging.js";
10
+ import { splitIntoBatches } from "./migrationHelper.js";
10
11
 
11
12
  export class UsersController {
12
13
  private config: AppwriteConfig;
@@ -47,8 +48,13 @@ export class UsersController {
47
48
  lastDocumentId = moreUsers.users[moreUsers.users.length - 1].$id;
48
49
  }
49
50
  console.log("Deleting all users");
51
+ const userPromises: Promise<string>[] = [];
50
52
  for (const user of allUsers) {
51
- await this.users.delete(user.$id);
53
+ userPromises.push(this.users.delete(user.$id));
54
+ }
55
+ const batchedUserPromises = splitIntoBatches(userPromises);
56
+ for (const batch of batchedUserPromises) {
57
+ await Promise.all(batch);
52
58
  }
53
59
  }
54
60