Skip to content

Commit

Permalink
Reduce Rollbar Usage (#8249)
Browse files Browse the repository at this point in the history
* resolve sequelize syntax errors

* remove email notifications

* cleaner solution

* lint
  • Loading branch information
timolegros authored Jun 26, 2024
1 parent 8cd12ef commit 74faa4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 31 deletions.
7 changes: 7 additions & 0 deletions packages/commonwealth/server/routes/getNewProfile.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { AppError } from '@hicommonwealth/core';
import type {
AddressAttributes,
CommentAttributes,
Expand Down Expand Up @@ -42,9 +43,15 @@ const getNewProfile = async (
next: NextFunction,
) => {
const { profileId } = req.query;

let profile: ProfileInstance;

if (profileId) {
const parsedInt = parseInt(profileId);
if (isNaN(parsedInt) || parsedInt !== parseFloat(profileId)) {
throw new AppError('Invalid profile id');
}

// @ts-expect-error StrictNullChecks
profile = await models.Profile.findOne({
where: {
Expand Down
6 changes: 6 additions & 0 deletions packages/commonwealth/server/routes/viewComments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { sanitizeDeletedComment } from 'server/util/sanitizeDeletedComment';

export const Errors = {
NoRootId: 'Must provide thread_id',
InvalidId: 'Invalid thread_id',
};

const viewComments = async (
Expand All @@ -21,6 +22,11 @@ const viewComments = async (
return next(new AppError(Errors.NoRootId));
}

const parsedInt = parseInt(threadId, 10);
if (isNaN(parsedInt) || parsedInt !== parseFloat(threadId)) {
return next(new AppError(Errors.InvalidId));
}

const comments = await models.Comment.findAll({
// @ts-expect-error StrictNullChecks
where: { community_id: community.id, thread_id: threadId },
Expand Down
31 changes: 0 additions & 31 deletions packages/commonwealth/server/util/emitNotifications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ import {
import Sequelize, { QueryTypes } from 'sequelize';
import { fileURLToPath } from 'url';
import { config } from '../config';
import {
createImmediateNotificationEmailObject,
sendImmediateNotificationEmail,
} from '../scripts/emails';
import { mapNotificationsDataToSubscriptions } from './subscriptionMapping';
import { dispatchWebhooks } from './webhooks/dispatchWebhook';

Expand Down Expand Up @@ -143,20 +139,6 @@ export default async function emitNotifications(
}
}

let msg;
try {
if (category_id !== 'snapshot-proposal') {
msg = await createImmediateNotificationEmailObject(
notification_data,
category_id,
models,
);
}
} catch (e) {
console.log('Error generating immediate notification email!');
console.trace(e);
}

let query = `INSERT INTO "NotificationsRead" (notification_id, subscription_id, is_read, user_id) VALUES `;
const replacements = [];
for (const subscription of subscriptions) {
Expand Down Expand Up @@ -194,19 +176,6 @@ export default async function emitNotifications(
}

if (config.SEND_WEBHOOKS_EMAILS) {
// emails
for (const subscription of subscriptions) {
// @ts-expect-error StrictNullChecks
if (msg && isChainEventData && chainEvent.community_id) {
// @ts-expect-error StrictNullChecks
msg.dynamic_template_data.notification.path = `${config.SERVER_URL}/${chainEvent.community_id}/notifications?id=${notification.id}`;
}
if (msg && subscription?.immediate_email && subscription?.User) {
// kick off async call and immediately return
sendImmediateNotificationEmail(subscription.User, msg);
}
}

// webhooks
try {
await dispatchWebhooks(notification_data_and_category);
Expand Down

0 comments on commit 74faa4c

Please sign in to comment.