@servable/tools 1.1.3 → 1.1.5
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/package.json
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
"type": "module",
|
|
4
4
|
"source": "src/index.js",
|
|
5
5
|
"main": "src/index.js",
|
|
6
|
-
"version": "1.1.
|
|
6
|
+
"version": "1.1.5",
|
|
7
7
|
"description": "Servable tools is a utility that builds a feature's manifest and documents it.",
|
|
8
8
|
"author": "Servable Community",
|
|
9
9
|
"license": "ISC",
|
|
@@ -60,6 +60,29 @@ export const performBatchOnQuery = async ({
|
|
|
60
60
|
} while (loops < expectedLoops || currentBatchResultsLength === batchSize);
|
|
61
61
|
};
|
|
62
62
|
|
|
63
|
+
export const performBatchOnQueryPerGroup = async ({
|
|
64
|
+
query,
|
|
65
|
+
batchSize = 100,
|
|
66
|
+
action
|
|
67
|
+
}) => {
|
|
68
|
+
const count = await query.count({ useMasterKey: true });
|
|
69
|
+
const expectedLoops = parseInt(count / batchSize);
|
|
70
|
+
let currentBatchResultsLength = 0;
|
|
71
|
+
let loops = 0;
|
|
72
|
+
|
|
73
|
+
do {
|
|
74
|
+
query.skip(batchSize * loops);
|
|
75
|
+
query.limit(batchSize);
|
|
76
|
+
const items = await query.find({ useMasterKey: true });
|
|
77
|
+
if (items && items.length) {
|
|
78
|
+
await action({ items })
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
currentBatchResultsLength = items.length;
|
|
82
|
+
loops++;
|
|
83
|
+
} while (loops < expectedLoops || currentBatchResultsLength === batchSize);
|
|
84
|
+
};
|
|
85
|
+
|
|
63
86
|
export const fetchObjectIfNeeded = async ({
|
|
64
87
|
object,
|
|
65
88
|
className,
|
|
@@ -111,8 +134,8 @@ export const destroyRowsWithQuery = async ({ query, limitPerBatch } = {}) => {
|
|
|
111
134
|
query
|
|
112
135
|
.limit(limitPerBatch)
|
|
113
136
|
.find()
|
|
114
|
-
.then(function(results) {
|
|
115
|
-
return Servable.App.Object.destroyAll(results).then(function() {
|
|
137
|
+
.then(function (results) {
|
|
138
|
+
return Servable.App.Object.destroyAll(results).then(function () {
|
|
116
139
|
return Promise.resolve(results.length);
|
|
117
140
|
});
|
|
118
141
|
});
|
|
@@ -122,7 +145,7 @@ export const destroyAllRowsWithQuery = async ({
|
|
|
122
145
|
query,
|
|
123
146
|
limitPerBatch = 1000
|
|
124
147
|
} = {}) => {
|
|
125
|
-
return destroyRowsWithQuery({ query, limitPerBatch }).then(function(count) {
|
|
148
|
+
return destroyRowsWithQuery({ query, limitPerBatch }).then(function (count) {
|
|
126
149
|
return count
|
|
127
150
|
? destroyAllRowsWithQuery({ query, limitPerBatch })
|
|
128
151
|
: Promise.resolve();
|