-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: fixed deletion of old messages function
- Loading branch information
Showing
5 changed files
with
35 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,6 @@ | ||
import db from '../../utils/Db.js'; | ||
|
||
const deleteExpiredInvites = async () => { | ||
export default async () => { | ||
const olderThan1h = new Date(Date.now() - 60 * 60 * 1_000); | ||
await db.hubInvites.deleteMany({ where: { expires: { lte: olderThan1h } } }).catch(() => null); | ||
}; | ||
export default deleteExpiredInvites; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,15 @@ | ||
import { captureException } from '@sentry/node'; | ||
import db from '../../utils/Db.js'; | ||
import { deleteMsgsFromDb } from '../../utils/Utils.js'; | ||
|
||
// Delete all network messages from db that are older than 24 hours old. | ||
const deleteOldMessages = async () => { | ||
export default async () => { | ||
const olderThan24h = Date.now() - 60 * 60 * 24_000; | ||
|
||
db.broadcastedMessages | ||
.findMany({ where: { createdAt: { lte: olderThan24h } } }) | ||
.then(async (m) => deleteMsgsFromDb(m.map(({ messageId }) => messageId))) | ||
.catch(captureException); | ||
}; | ||
const data = await db.broadcastedMessages.findMany({ | ||
where: { createdAt: { lte: olderThan24h } }, | ||
}); | ||
await db.broadcastedMessages.deleteMany({ where: { createdAt: { lte: olderThan24h } } }); | ||
|
||
export default deleteOldMessages; | ||
await db.originalMessages.deleteMany({ | ||
where: { messageId: { in: data.map((d) => d.originalMsgId) } }, | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters