Skip to content

Commit

Permalink
fix search index when updating thread/comment
Browse files Browse the repository at this point in the history
  • Loading branch information
timolegros committed Sep 11, 2024
1 parent ada4d86 commit 3cc9b75
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion libs/model/src/comment/UpdateComment.command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import * as schemas from '@hicommonwealth/schemas';
import { models } from '../database';
import { isAuthorized, type AuthContext } from '../middleware';
import { mustBeAuthorized } from '../middleware/guards';
import { getCommentSearchVector } from '../models';
import {
emitMentions,
findMentionDiff,
Expand Down Expand Up @@ -47,7 +48,7 @@ export function UpdateComment(): Command<
// == mutation transaction boundary ==
await models.sequelize.transaction(async (transaction) => {
await models.Comment.update(
{ text, plaintext },
{ text, plaintext, search: getCommentSearchVector(text) },
{ where: { id: comment.id }, transaction },
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
UserInstance,
emitMentions,
findMentionDiff,
getThreadSearchVector,
parseUserMentions,
} from '@hicommonwealth/model';
import { renderQuillDeltaToText } from '@hicommonwealth/shared';
Expand Down Expand Up @@ -114,11 +115,12 @@ export async function __updateThread(
// check if thread is part of a contest topic
const contestManagers = await this.models.sequelize.query(
`
SELECT cm.contest_address FROM "Threads" t
JOIN "ContestTopics" ct on ct.topic_id = t.topic_id
JOIN "ContestManagers" cm on cm.contest_address = ct.contest_address
WHERE t.id = :thread_id
`,
SELECT cm.contest_address
FROM "Threads" t
JOIN "ContestTopics" ct on ct.topic_id = t.topic_id
JOIN "ContestManagers" cm on cm.contest_address = ct.contest_address
WHERE t.id = :thread_id
`,
{
type: QueryTypes.SELECT,
replacements: {
Expand Down Expand Up @@ -225,6 +227,7 @@ export async function __updateThread(
await thread.update(
{
...toUpdate,
search: getThreadSearchVector(title || thread.title, body),
last_edited: Sequelize.literal('CURRENT_TIMESTAMP'),
},
{ transaction },
Expand Down

0 comments on commit 3cc9b75

Please sign in to comment.