Throttle email notifications upon updating document frequently (#4026)

* feat: add needed columns for throttling notifs

* feat: update model

* feat: deliver only one notif in a 12 hour window

* fix: address review comments

* prevent retry if notification update fails
* fix type compatibility instead of circumventing it
* add index for emailedAt

* fix: add metadata attr to EmailProps

* chore: decouple metadata from EmailProps

* chore: add test

* chore: revert sending metadata in props
This commit is contained in:
Apoorv Mishra
2022-09-07 16:51:30 +05:30
committed by GitHub
parent e4023d87e2
commit 1e39b564fe
7 changed files with 264 additions and 17 deletions

View File

@@ -9,7 +9,10 @@ import {
BelongsTo,
DataType,
Default,
AllowNull,
} from "sequelize-typescript";
import Document from "./Document";
import Team from "./Team";
import User from "./User";
import Fix from "./decorators/Fix";
@@ -26,15 +29,20 @@ class Notification extends Model {
@Column(DataType.UUID)
id: string;
@AllowNull
@Column
emailedAt: Date;
@AllowNull
@Column
viewedAt: Date;
@CreatedAt
createdAt: Date;
@Column
event: string;
@Column
email: boolean;
// associations
@BelongsTo(() => User, "userId")
@@ -47,9 +55,25 @@ class Notification extends Model {
@BelongsTo(() => User, "actorId")
actor: User;
@AllowNull
@ForeignKey(() => User)
@Column(DataType.UUID)
actorId: string;
@BelongsTo(() => Document, "documentId")
document: Document;
@AllowNull
@ForeignKey(() => Document)
@Column(DataType.UUID)
documentId: string;
@BelongsTo(() => Team, "teamId")
team: Team;
@ForeignKey(() => Team)
@Column(DataType.UUID)
teamId: string;
}
export default Notification;