3
0
Fork 0
mirror of https://github.com/ZeppelinBot/Zeppelin.git synced 2025-05-11 04:45:02 +00:00

Add support for server-specific timezone and date format settings

This commit is contained in:
Dragory 2020-08-10 00:24:06 +03:00
parent ddbbc543c2
commit c67a1df11d
No known key found for this signature in database
GPG key ID: 5F387BA66DF8AAC1
51 changed files with 326 additions and 168 deletions

View file

@ -2,7 +2,7 @@ import { connection } from "../db";
import { getRepository, In } from "typeorm";
import { Config } from "../entities/Config";
import moment from "moment-timezone";
import { DBDateFormat } from "../../utils";
import { DBDateFormat } from "../../utils/dateFormats";
const CLEAN_PER_LOOP = 50;
@ -13,7 +13,8 @@ export async function cleanupConfigs() {
let rows;
// >1 month old: 1 config retained per month
const oneMonthCutoff = moment()
const oneMonthCutoff = moment
.utc()
.subtract(30, "days")
.format(DBDateFormat);
do {
@ -53,7 +54,8 @@ export async function cleanupConfigs() {
} while (rows.length === CLEAN_PER_LOOP);
// >2 weeks old: 1 config retained per day
const twoWeekCutoff = moment()
const twoWeekCutoff = moment
.utc()
.subtract(2, "weeks")
.format(DBDateFormat);
do {

View file

@ -1,8 +1,9 @@
import { DAYS, DBDateFormat, MINUTES } from "../../utils";
import { DAYS, MINUTES } from "../../utils";
import { getRepository, In } from "typeorm";
import { SavedMessage } from "../entities/SavedMessage";
import moment from "moment-timezone";
import { connection } from "../db";
import { DBDateFormat } from "../../utils/dateFormats";
/**
* How long message edits, deletions, etc. will include the original message content.
@ -18,13 +19,16 @@ export async function cleanupMessages(): Promise<number> {
const messagesRepository = getRepository(SavedMessage);
const deletedAtThreshold = moment()
const deletedAtThreshold = moment
.utc()
.subtract(DELETED_MESSAGE_RETENTION_PERIOD, "ms")
.format(DBDateFormat);
const postedAtThreshold = moment()
const postedAtThreshold = moment
.utc()
.subtract(RETENTION_PERIOD, "ms")
.format(DBDateFormat);
const botPostedAtThreshold = moment()
const botPostedAtThreshold = moment
.utc()
.subtract(BOT_MESSAGE_RETENTION_PERIOD, "ms")
.format(DBDateFormat);

View file

@ -1,8 +1,9 @@
import { getRepository, In } from "typeorm";
import moment from "moment-timezone";
import { NicknameHistoryEntry } from "../entities/NicknameHistoryEntry";
import { DAYS, DBDateFormat } from "../../utils";
import { DAYS } from "../../utils";
import { connection } from "../db";
import { DBDateFormat } from "../../utils/dateFormats";
export const NICKNAME_RETENTION_PERIOD = 30 * DAYS;
const CLEAN_PER_LOOP = 500;
@ -11,7 +12,8 @@ export async function cleanupNicknames(): Promise<number> {
let cleaned = 0;
const nicknameHistoryRepository = getRepository(NicknameHistoryEntry);
const dateThreshold = moment()
const dateThreshold = moment
.utc()
.subtract(NICKNAME_RETENTION_PERIOD, "ms")
.format(DBDateFormat);

View file

@ -1,8 +1,9 @@
import { getRepository, In } from "typeorm";
import moment from "moment-timezone";
import { UsernameHistoryEntry } from "../entities/UsernameHistoryEntry";
import { DAYS, DBDateFormat } from "../../utils";
import { DAYS } from "../../utils";
import { connection } from "../db";
import { DBDateFormat } from "../../utils/dateFormats";
export const USERNAME_RETENTION_PERIOD = 30 * DAYS;
const CLEAN_PER_LOOP = 500;
@ -11,7 +12,8 @@ export async function cleanupUsernames(): Promise<number> {
let cleaned = 0;
const usernameHistoryRepository = getRepository(UsernameHistoryEntry);
const dateThreshold = moment()
const dateThreshold = moment
.utc()
.subtract(USERNAME_RETENTION_PERIOD, "ms")
.format(DBDateFormat);