MongooseCache resubscription
This commit is contained in:
parent
f3f11adb38
commit
953d7bd3d2
@ -20,6 +20,7 @@
|
||||
"lambert-db": "^1.1.8",
|
||||
"lambert-server": "^1.1.7",
|
||||
"missing-native-js-functions": "^1.2.3",
|
||||
"mongoose-autopopulate": "^0.12.3",
|
||||
"node-fetch": "^2.6.1",
|
||||
"typescript": "^4.2.3",
|
||||
"uuid": "^8.3.2",
|
||||
@ -27,6 +28,7 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/jsonwebtoken": "^8.5.0",
|
||||
"@types/mongoose-autopopulate": "^0.10.1",
|
||||
"@types/uuid": "^8.3.0",
|
||||
"@types/ws": "^7.4.0"
|
||||
}
|
||||
|
@ -26,14 +26,28 @@ export async function setupListener(this: WebSocket) {
|
||||
[
|
||||
{
|
||||
$match: {
|
||||
$or: [{ "fullDocument.guild_id": { $in: guilds } }, { "fullDocument.user_id": this.user_id }],
|
||||
},
|
||||
},
|
||||
$or: [{ "fullDocument.guild_id": { $in: guilds } }, { "fullDocument.user_id": user.id }]
|
||||
}
|
||||
}
|
||||
],
|
||||
{ onlyEvents: true }
|
||||
{
|
||||
onlyEvents: true
|
||||
}
|
||||
);
|
||||
|
||||
await eventStream.init();
|
||||
eventStream.on("insert", dispatch.bind(this));
|
||||
eventStream.on("insert", async (document) => {
|
||||
dispatch.call(this, document);
|
||||
|
||||
const newUser = await UserModel.findOne({ id: user.id }).lean().exec();
|
||||
var newGuilds = user.guilds;
|
||||
|
||||
if (shard_count) {
|
||||
newGuilds = user.guilds.filter((x) => (BigInt(x) >> 22n) % shard_count === shard_id);
|
||||
}
|
||||
|
||||
eventStream.changeStream([{ $match: { $or: [{ "fullDocument.guild_id": { $in: newGuilds } }, { "fullDocument.user_id": newUser.id }] } }]);
|
||||
});
|
||||
|
||||
this.once("close", () => eventStream.destroy());
|
||||
}
|
||||
@ -180,6 +194,6 @@ export async function dispatch(this: WebSocket, document: Event) {
|
||||
op: OPCODES.Dispatch,
|
||||
t: document.event,
|
||||
d: document.data,
|
||||
s: this.sequence++,
|
||||
s: this.sequence++
|
||||
});
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user