From 88dd0c61729b91c0c36650bc41592b522b11365f Mon Sep 17 00:00:00 2001 From: TheEssem Date: Fri, 24 Apr 2020 15:25:27 -0500 Subject: [PATCH] Use lean() method on read-only database calls --- commands/help.js | 2 +- events/messageCreate.js | 2 +- utils/twitter.js | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/commands/help.js b/commands/help.js index 53fed78..661abd1 100644 --- a/commands/help.js +++ b/commands/help.js @@ -6,7 +6,7 @@ const paginator = require("../utils/pagination/pagination.js"); const tips = ["You can change the bot's prefix using the prefix command.", "Image commands also work with images previously posted in that channel.", "You can use the tags commands to save things for later use.", "You can visit https://projectlounge.pw/esmBot/help.html for a web version of this command list.", "You can view a command's aliases by putting the command name after the help command (e.g. help image).", "Parameters wrapped in [] are required, while parameters wrapped in {} are optional."]; exports.run = async (message, args) => { - const guild = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0]; + const guild = (await database.guilds.find({ id: message.channel.guild.id }).lean().exec())[0]; const commands = collections.commands; const aliases = collections.aliases; if (args.length !== 0 && (commands.has(args[0].toLowerCase()) || aliases.has(args[0].toLowerCase()))) { diff --git a/events/messageCreate.js b/events/messageCreate.js index a6a0ac8..9cab702 100644 --- a/events/messageCreate.js +++ b/events/messageCreate.js @@ -16,7 +16,7 @@ module.exports = async (message) => { if (!message.channel.guild.members.get(client.user.id).permission.has("sendMessages") || !message.channel.permissionsOf(client.user.id).has("sendMessages")) return; // prefix can be a mention or a set of special characters - const guildDB = (await database.guilds.find({ id: message.channel.guild.id }).exec())[0]; + const guildDB = (await database.guilds.find({ id: message.channel.guild.id }).lean().exec())[0]; const prefixMention = new RegExp(`^<@!?${client.user.id}> `); const prefix = prefixMention.test(message.content) ? message.content.match(prefixMention)[0] : guildDB.prefix; diff --git a/utils/twitter.js b/utils/twitter.js index 216525d..3068025 100644 --- a/utils/twitter.js +++ b/utils/twitter.js @@ -8,7 +8,7 @@ const client = new Twitter({ }); exports.client = client; exports.active = false; -database.tweets.find({ enabled: true }, (error, docs) => { +database.tweets.find({ enabled: true }).lean().exec((error, docs) => { if (error) throw error; exports.tweets = docs[0]; }); \ No newline at end of file