perf: Narrow scopes of Slack hook queries

This commit is contained in:
Tom Moor
2023-08-06 11:54:48 -04:00
parent d8f1f55a80
commit 6c4e2a9d11

View File

@@ -1,6 +1,7 @@
import { t } from "i18next";
import Router from "koa-router";
import { escapeRegExp } from "lodash";
import { Op } from "sequelize";
import { IntegrationService } from "@shared/types";
import env from "@server/env";
import { AuthenticationError, InvalidRequestError } from "@server/errors";
@@ -196,6 +197,7 @@ router.post("hooks.slack", async (ctx: APIContext) => {
// via integration
const integration = await Integration.findOne({
where: {
service: IntegrationService.Slack,
settings: {
serviceTeamId: team_id,
},
@@ -259,6 +261,7 @@ router.post("hooks.slack", async (ctx: APIContext) => {
if (!user) {
const auth = await IntegrationAuthentication.findOne({
where: {
scopes: { [Op.contains]: ["identity.email"] },
service: IntegrationService.Slack,
teamId: team.id,
},