Revert "Fix race condition in name collector to close #14"
This reverts commit bb3afc2bf6
.
This commit is contained in:
parent
18b034ed58
commit
dd5fdc521a
|
@ -1,13 +1,7 @@
|
|||
var nameCollector = module.exports = {
|
||||
collection: mdbClient.db('heroku_jrtfvpd9').collection('ppl'),
|
||||
buffer: [],
|
||||
operationPending: false,
|
||||
collect: async function (participant) {
|
||||
if (config.testmode) return;
|
||||
|
||||
if (this.operationPending) { this.buffer.push(participant); return }
|
||||
this.operationPending = true;
|
||||
|
||||
if (participant.name == "Anonymous" || participant.name == "Anonymoose") return;
|
||||
|
||||
var newMsg = function(continued){
|
||||
|
@ -21,25 +15,23 @@ var nameCollector = module.exports = {
|
|||
// update person
|
||||
if (document.names.includes(participant.name)) return;
|
||||
document.names.push(participant.name);
|
||||
await this.collection.updateOne({_id: participant._id}, {$set:{names: document.names}});
|
||||
this.collection.updateOne({_id: participant._id}, {$set:{names: document.names}});
|
||||
|
||||
let message = await dClient.channels.get(config.channels.name_collection).messages.fetch(document.discord_msg_id);
|
||||
try {
|
||||
await message.edit(message.content + ', ' + participant.name);
|
||||
} catch(e) {
|
||||
let message = await newMsg(true);
|
||||
await this.collection.updateOne({_id: participant._id}, {$set:{discord_msg_id: message.id}});
|
||||
this.collection.updateOne({_id: participant._id}, {$set:{discord_msg_id: message.id}});
|
||||
}
|
||||
} else {
|
||||
// add new person
|
||||
let message = await newMsg();
|
||||
await nameCollector.collection.insertOne({
|
||||
nameCollector.collection.insertOne({
|
||||
_id: participant._id,
|
||||
discord_msg_id: message.id,
|
||||
names: [participant.name]
|
||||
});
|
||||
}
|
||||
if (this.buffer.length) this.collect(this.buffer.shift());
|
||||
else this.operationPending = false;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue