appwrite-utils-cli 0.10.83 → 0.10.85
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 +1 -0
- package/dist/collections/methods.js +16 -6
- package/package.json +1 -1
- package/src/collections/methods.ts +23 -10
package/README.md
CHANGED
@@ -150,6 +150,7 @@ This updated CLI ensures that developers have robust tools at their fingertips t
|
|
150
150
|
|
151
151
|
## Changelog
|
152
152
|
|
153
|
+
- 0.10.85: Added logging to `wipeCollection`
|
153
154
|
- 0.10.83: Actually fixed the import oops
|
154
155
|
- 0.10.82: Fixed the `lodash` import, replaced with `es-toolkit`
|
155
156
|
- 0.10.81: Fixed `wipeCollection` -- it wasn't properly deleting all files in a loop
|
@@ -3,7 +3,7 @@ import { nameToIdMapping, processQueue } from "../migrations/queue.js";
|
|
3
3
|
import { createUpdateCollectionAttributes } from "./attributes.js";
|
4
4
|
import { createOrUpdateIndexes } from "./indexes.js";
|
5
5
|
import { SchemaGenerator } from "../migrations/schemaStrings.js";
|
6
|
-
import { isNull, isUndefined, isNil, isPlainObject, isString, isJSONValue, } from "es-toolkit";
|
6
|
+
import { isNull, isUndefined, isNil, isPlainObject, isString, isJSONValue, chunk, } from "es-toolkit";
|
7
7
|
import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
8
8
|
export const documentExists = async (db, dbId, targetCollectionId, toCreateObject) => {
|
9
9
|
const collection = await db.getCollection(dbId, targetCollectionId);
|
@@ -95,18 +95,23 @@ async function wipeDocumentsFromCollection(database, databaseId, collectionId) {
|
|
95
95
|
? initialDocuments.documents[initialDocuments.documents.length - 1].$id
|
96
96
|
: undefined;
|
97
97
|
while (cursor) {
|
98
|
-
const docsResponse = await database.listDocuments(databaseId, collectionId, [Query.limit(1000)]);
|
98
|
+
const docsResponse = await database.listDocuments(databaseId, collectionId, [Query.limit(1000), ...(cursor ? [Query.cursorAfter(cursor)] : [])]);
|
99
99
|
documents.push(...docsResponse.documents);
|
100
100
|
totalDocuments = documents.length;
|
101
101
|
cursor =
|
102
102
|
docsResponse.documents.length >= 1000
|
103
103
|
? docsResponse.documents[docsResponse.documents.length - 1].$id
|
104
104
|
: undefined;
|
105
|
+
if (totalDocuments % 10000 === 0) {
|
106
|
+
console.log(`Found ${totalDocuments} documents...`);
|
107
|
+
}
|
105
108
|
}
|
106
109
|
console.log(`Found ${totalDocuments} documents to delete`);
|
107
110
|
const maxStackSize = 50; // Reduced batch size
|
108
|
-
|
109
|
-
|
111
|
+
const docBatches = chunk(documents, maxStackSize);
|
112
|
+
const quarterBatchSize = Math.ceil(docBatches.length / 4);
|
113
|
+
for (let i = 0; i < docBatches.length; i++) {
|
114
|
+
const batch = docBatches[i];
|
110
115
|
const deletePromises = batch.map(async (doc) => {
|
111
116
|
try {
|
112
117
|
await tryAwaitWithRetry(async () => database.deleteDocument(databaseId, collectionId, doc.$id));
|
@@ -119,8 +124,13 @@ async function wipeDocumentsFromCollection(database, databaseId, collectionId) {
|
|
119
124
|
}
|
120
125
|
});
|
121
126
|
await Promise.all(deletePromises);
|
122
|
-
await delay(
|
123
|
-
|
127
|
+
await delay(50); // Increased delay between batches
|
128
|
+
// Log at 25%, 50%, 75% and 100% completion
|
129
|
+
if ((i + 1) % quarterBatchSize === 0 || i === docBatches.length - 1) {
|
130
|
+
const percentComplete = Math.round(((i + 1) / docBatches.length) * 100);
|
131
|
+
const documentsProcessed = Math.min((i + 1) * maxStackSize, totalDocuments);
|
132
|
+
console.log(`Deleted ${documentsProcessed} documents (${percentComplete}% complete)`);
|
133
|
+
}
|
124
134
|
}
|
125
135
|
console.log(`Completed deletion of ${totalDocuments} documents from collection ${collectionId}`);
|
126
136
|
}
|
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.10.
|
4
|
+
"version": "0.10.85",
|
5
5
|
"main": "src/main.ts",
|
6
6
|
"type": "module",
|
7
7
|
"repository": {
|
@@ -18,6 +18,7 @@ import {
|
|
18
18
|
isPlainObject,
|
19
19
|
isString,
|
20
20
|
isJSONValue,
|
21
|
+
chunk,
|
21
22
|
} from "es-toolkit";
|
22
23
|
import { delay, tryAwaitWithRetry } from "../utils/helperFunctions.js";
|
23
24
|
|
@@ -157,7 +158,7 @@ async function wipeDocumentsFromCollection(
|
|
157
158
|
const docsResponse = await database.listDocuments(
|
158
159
|
databaseId,
|
159
160
|
collectionId,
|
160
|
-
[Query.limit(1000)]
|
161
|
+
[Query.limit(1000), ...(cursor ? [Query.cursorAfter(cursor)] : [])]
|
161
162
|
);
|
162
163
|
documents.push(...docsResponse.documents);
|
163
164
|
totalDocuments = documents.length;
|
@@ -165,13 +166,19 @@ async function wipeDocumentsFromCollection(
|
|
165
166
|
docsResponse.documents.length >= 1000
|
166
167
|
? docsResponse.documents[docsResponse.documents.length - 1].$id
|
167
168
|
: undefined;
|
169
|
+
if (totalDocuments % 10000 === 0) {
|
170
|
+
console.log(`Found ${totalDocuments} documents...`);
|
171
|
+
}
|
168
172
|
}
|
169
173
|
|
170
174
|
console.log(`Found ${totalDocuments} documents to delete`);
|
171
175
|
|
172
176
|
const maxStackSize = 50; // Reduced batch size
|
173
|
-
|
174
|
-
|
177
|
+
const docBatches = chunk(documents, maxStackSize);
|
178
|
+
const quarterBatchSize = Math.ceil(docBatches.length / 4);
|
179
|
+
|
180
|
+
for (let i = 0; i < docBatches.length; i++) {
|
181
|
+
const batch = docBatches[i];
|
175
182
|
const deletePromises = batch.map(async (doc) => {
|
176
183
|
try {
|
177
184
|
await tryAwaitWithRetry(async () =>
|
@@ -193,13 +200,19 @@ async function wipeDocumentsFromCollection(
|
|
193
200
|
});
|
194
201
|
|
195
202
|
await Promise.all(deletePromises);
|
196
|
-
await delay(
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
+
await delay(50); // Increased delay between batches
|
204
|
+
|
205
|
+
// Log at 25%, 50%, 75% and 100% completion
|
206
|
+
if ((i + 1) % quarterBatchSize === 0 || i === docBatches.length - 1) {
|
207
|
+
const percentComplete = Math.round(((i + 1) / docBatches.length) * 100);
|
208
|
+
const documentsProcessed = Math.min(
|
209
|
+
(i + 1) * maxStackSize,
|
210
|
+
totalDocuments
|
211
|
+
);
|
212
|
+
console.log(
|
213
|
+
`Deleted ${documentsProcessed} documents (${percentComplete}% complete)`
|
214
|
+
);
|
215
|
+
}
|
203
216
|
}
|
204
217
|
|
205
218
|
console.log(
|