@@ -37,12 +37,14 @@ const {
37
37
teamsCreate
38
38
} = require("./teams");
39
39
40
- const POOL_DEBOUNCE = 2000; // in milliseconds
41
- const POOL_MAX_DEBOUNCES = 30;
40
+ const STEP_SIZE = 100; // Resources
41
+ const POOL_DEBOUNCE = 2000; // Milliseconds
42
+
43
+ let poolMaxDebounces = 30;
42
44
43
45
const awaitPools = {
44
46
wipeAttributes: async (databaseId, collectionId, iteration = 1) => {
45
- if (iteration > POOL_MAX_DEBOUNCES ) {
47
+ if (iteration > poolMaxDebounces ) {
46
48
return false;
47
49
}
48
50
@@ -58,11 +60,18 @@ const awaitPools = {
58
60
return true;
59
61
}
60
62
63
+ let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
64
+ if (steps > 1 && iteration === 1) {
65
+ poolMaxDebounces *= steps;
66
+
67
+ log('Found a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
68
+ }
69
+
61
70
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
62
71
return await awaitPools.wipeAttributes(databaseId, collectionId, iteration + 1);
63
72
},
64
73
wipeIndexes: async (databaseId, collectionId, iteration = 1) => {
65
- if (iteration > POOL_MAX_DEBOUNCES ) {
74
+ if (iteration > poolMaxDebounces ) {
66
75
return false;
67
76
}
68
77
@@ -78,16 +87,31 @@ const awaitPools = {
78
87
return true;
79
88
}
80
89
90
+ let steps = Math.max(1, Math.ceil(total / STEP_SIZE));
91
+ if (steps > 1 && iteration === 1) {
92
+ poolMaxDebounces *= steps;
93
+
94
+ log('Found a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
95
+ }
96
+
81
97
await new Promise(resolve => setTimeout(resolve, POOL_DEBOUNCE));
82
98
return await awaitPools.wipeIndexes(databaseId, collectionId, iteration + 1);
83
99
},
84
100
expectAttributes: async (databaseId, collectionId, attributeKeys, iteration = 1) => {
85
- if (iteration > POOL_MAX_DEBOUNCES ) {
101
+ if (iteration > poolMaxDebounces ) {
86
102
return false;
87
103
}
88
104
89
105
// TODO: Pagination?
90
106
const { attributes: remoteAttributes } = await databasesListAttributes({
107
+ let steps = Math.max(1, Math.ceil(attributeKeys.length / STEP_SIZE));
108
+ if (steps > 1 && iteration === 1) {
109
+ poolMaxDebounces *= steps;
110
+
111
+ log('Creating a large number of attributes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
112
+ }
113
+
114
+ const { attributes } = await paginate(databasesListAttributes, {
91
115
databaseId,
92
116
collectionId,
93
117
queries: ['limit(100)'],
@@ -114,12 +138,19 @@ const awaitPools = {
114
138
return await awaitPools.expectAttributes(databaseId, collectionId, attributeKeys, iteration + 1);
115
139
},
116
140
expectIndexes: async (databaseId, collectionId, indexKeys, iteration = 1) => {
117
- if (iteration > POOL_MAX_DEBOUNCES ) {
141
+ if (iteration > poolMaxDebounces ) {
118
142
return false;
119
143
}
120
144
121
145
// TODO: Pagination?
122
146
const { indexes: remoteIndexes } = await databasesListIndexes({
147
+ let steps = Math.max(1, Math.ceil(indexKeys.length / STEP_SIZE));
148
+ if (steps > 1 && iteration === 1) {
149
+ poolMaxDebounces *= steps;
150
+
151
+ log('Creating a large number of indexes, increasing timeout to ' + (poolMaxDebounces * POOL_DEBOUNCE / 1000 / 60) + ' minutes')
152
+ }
153
+
123
154
databaseId,
124
155
collectionId,
125
156
queries: ['limit(100)'],
0 commit comments