bulltrackers-module 1.0.136 → 1.0.137
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.
|
@@ -59,14 +59,30 @@ async function handleVerify(task, taskId, { db, logger, ...dependencies }, confi
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
|
|
62
|
+
// --- START FIX: MODIFIED FOR SHARDING ---
|
|
62
63
|
if (Object.keys(usernameMap).length) {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
64
|
+
// Group updates by shard
|
|
65
|
+
const shardedUpdates = {};
|
|
66
|
+
for (const cid in usernameMap) {
|
|
67
|
+
// Re-implement the sharding logic here
|
|
68
|
+
const shardId = `cid_map_shard_${Math.floor(parseInt(cid) / 10000) % 10}`;
|
|
69
|
+
if (!shardedUpdates[shardId]) {
|
|
70
|
+
shardedUpdates[shardId] = {};
|
|
71
|
+
}
|
|
72
|
+
shardedUpdates[shardId][cid] = usernameMap[cid];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
// Write each shard to its own document
|
|
76
|
+
for (const shardId in shardedUpdates) {
|
|
77
|
+
const mapRef = db.collection(config.FIRESTORE_COLLECTION_USERNAME_MAP).doc(shardId);
|
|
78
|
+
batch.set(mapRef, shardedUpdates[shardId], { merge: true });
|
|
79
|
+
}
|
|
80
|
+
logger.log('INFO', `[VERIFY] Staging username updates across ${Object.keys(shardedUpdates).length} shards.`);
|
|
66
81
|
}
|
|
82
|
+
// --- END FIX ---
|
|
67
83
|
|
|
68
84
|
await batch.commit();
|
|
69
85
|
if (validUserCount) logger.log('INFO', `[VERIFY] Verified and stored ${validUserCount} new ${userType} users.`);
|
|
70
86
|
}
|
|
71
87
|
|
|
72
|
-
module.exports = { handleVerify };
|
|
88
|
+
module.exports = { handleVerify };
|
|
@@ -31,6 +31,13 @@ class FirestoreBatchManager {
|
|
|
31
31
|
logger.log('INFO', 'FirestoreBatchManager initialized.');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
// --- START FIX: ADDED SHARDING HELPER ---
|
|
35
|
+
_getUsernameShardId(cid) {
|
|
36
|
+
// Shard across 10 documents (supports ~200k users assuming 50 bytes/user)
|
|
37
|
+
return `cid_map_shard_${Math.floor(parseInt(cid) / 10000) % 10}`;
|
|
38
|
+
}
|
|
39
|
+
// --- END FIX ---
|
|
40
|
+
|
|
34
41
|
_scheduleFlush() {
|
|
35
42
|
if (!this.batchTimeout) this.batchTimeout = setTimeout(() => this.flushBatches(), this.config.TASK_ENGINE_FLUSH_INTERVAL_MS);
|
|
36
43
|
}
|
|
@@ -40,6 +47,7 @@ class FirestoreBatchManager {
|
|
|
40
47
|
this.usernameMap.clear();
|
|
41
48
|
this.logger.log('INFO', '[BATCH] Refreshing username map from Firestore...');
|
|
42
49
|
try {
|
|
50
|
+
// This correctly gets ALL documents (shards) in the collection
|
|
43
51
|
const snapshot = await this.db.collection(this.usernameMapCollectionName).get();
|
|
44
52
|
snapshot.forEach(doc => {
|
|
45
53
|
const data = doc.data();
|
|
@@ -54,14 +62,23 @@ class FirestoreBatchManager {
|
|
|
54
62
|
|
|
55
63
|
getUsername(cid) { return this.usernameMap.get(String(cid)); }
|
|
56
64
|
|
|
65
|
+
// --- START FIX: MODIFIED FOR SHARDING ---
|
|
57
66
|
addUsernameMapUpdate(cid, username) {
|
|
58
67
|
if (!username) return;
|
|
59
68
|
const cidStr = String(cid);
|
|
60
69
|
this.usernameMap.set(cidStr, username);
|
|
61
|
-
|
|
62
|
-
|
|
70
|
+
|
|
71
|
+
// Organize updates by shard ID
|
|
72
|
+
const shardId = this._getUsernameShardId(cidStr);
|
|
73
|
+
if (!this.usernameMapUpdates[shardId]) {
|
|
74
|
+
this.usernameMapUpdates[shardId] = {};
|
|
75
|
+
}
|
|
76
|
+
this.usernameMapUpdates[shardId][cidStr] = { username };
|
|
77
|
+
|
|
78
|
+
this.logger.log('TRACE', `[BATCH] Queued username update for ${cidStr} in ${shardId}.`);
|
|
63
79
|
this._scheduleFlush();
|
|
64
80
|
}
|
|
81
|
+
// --- END FIX ---
|
|
65
82
|
|
|
66
83
|
async addToTradingHistoryBatch(userId, blockId, date, historyData, userType) {
|
|
67
84
|
const collection = userType === 'speculator' ? this.speculatorHistoryCollectionName : this.normalHistoryCollectionName;
|
|
@@ -151,12 +168,22 @@ class FirestoreBatchManager {
|
|
|
151
168
|
delete this.speculatorTimestampFixBatch[docPath];
|
|
152
169
|
}
|
|
153
170
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
171
|
+
// --- START FIX: MODIFIED FOR SHARDING ---
|
|
172
|
+
// Loop over each shardId in the updates object
|
|
173
|
+
for (const shardId in this.usernameMapUpdates) {
|
|
174
|
+
const updates = this.usernameMapUpdates[shardId];
|
|
175
|
+
if (updates && Object.keys(updates).length > 0) {
|
|
176
|
+
firestoreBatch.set(
|
|
177
|
+
this.db.collection(this.usernameMapCollectionName).doc(shardId),
|
|
178
|
+
updates,
|
|
179
|
+
{ merge: true }
|
|
180
|
+
);
|
|
181
|
+
batchOps++;
|
|
182
|
+
this.logger.log('INFO', `[BATCH] Flushing ${Object.keys(updates).length} username updates to ${shardId}.`);
|
|
183
|
+
}
|
|
159
184
|
}
|
|
185
|
+
this.usernameMapUpdates = {}; // Clear updates after staging them
|
|
186
|
+
// --- END FIX ---
|
|
160
187
|
|
|
161
188
|
if (this.processedSpeculatorCids.size) {
|
|
162
189
|
const cids = Array.from(this.processedSpeculatorCids);
|
|
@@ -180,4 +207,4 @@ class FirestoreBatchManager {
|
|
|
180
207
|
}
|
|
181
208
|
}
|
|
182
209
|
|
|
183
|
-
module.exports = { FirestoreBatchManager };
|
|
210
|
+
module.exports = { FirestoreBatchManager };
|