mirror of
https://iceshrimp.dev/iceshrimp/iceshrimp
synced 2024-11-27 14:28:08 +09:00
[backend] Dynamically import redisClient in postgre.ts and dependencies
This fixes unnecessary redisClient instances being created during migration runs, which previously prevented the revertmigration command from exiting by itself due to a TypeORM inconsistency between migration:run and migration:revert.
This commit is contained in:
parent
1488529228
commit
2baa787b72
@ -75,7 +75,6 @@ import { NoteEdit } from "@/models/entities/note-edit.js";
|
||||
import { entities as charts } from "@/services/chart/entities.js";
|
||||
import { envOption } from "../env.js";
|
||||
import { dbLogger } from "./logger.js";
|
||||
import { redisClient } from "./redis.js";
|
||||
import { OAuthApp } from "@/models/entities/oauth-app.js";
|
||||
import { OAuthToken } from "@/models/entities/oauth-token.js";
|
||||
|
||||
@ -238,6 +237,7 @@ export async function initDb(force = false) {
|
||||
|
||||
export async function resetDb() {
|
||||
const reset = async () => {
|
||||
const { redisClient } = await import("./redis.js");
|
||||
await redisClient.flushdb();
|
||||
const tables = await db.query(`SELECT relname AS "table"
|
||||
FROM pg_class C LEFT JOIN pg_namespace N ON (N.oid = C.relnamespace)
|
||||
|
@ -1,5 +1,4 @@
|
||||
import { MigrationInterface, QueryRunner } from "typeorm";
|
||||
import { redisClient } from "../db/redis.js";
|
||||
|
||||
export class MoveAntennaToCache1695749948350 implements MigrationInterface {
|
||||
name = "MoveAntennaToCache1695749948350";
|
||||
@ -19,6 +18,7 @@ export class MoveAntennaToCache1695749948350 implements MigrationInterface {
|
||||
console.log('ANTENNA_MIGRATION_SKIP = true, skipping antenna note migration');
|
||||
}
|
||||
else {
|
||||
const { redisClient } = await import("../db/redis.js");
|
||||
const total = await queryRunner.query(`SELECT COUNT(1) FROM "antenna_note"`)
|
||||
.then(p => p[0]['count']);
|
||||
|
||||
@ -41,6 +41,8 @@ export class MoveAntennaToCache1695749948350 implements MigrationInterface {
|
||||
|
||||
query = `SELECT "id", "noteId", "antennaId" FROM "antenna_note" WHERE "id" > '${res.at(-1).id}' ORDER BY "id" ASC LIMIT ${Math.min(readLimit, remaining)}`;
|
||||
}
|
||||
|
||||
redisClient.quit();
|
||||
}
|
||||
|
||||
await queryRunner.query(`DROP TABLE IF EXISTS "antenna_note"`);
|
||||
|
@ -15,7 +15,6 @@ import {
|
||||
subtractTime,
|
||||
addTime,
|
||||
} from "@/prelude/time.js";
|
||||
import { getChartInsertLock } from "@/misc/app-lock.js";
|
||||
import { db } from "@/db/postgre.js";
|
||||
import promiseLimit from "promise-limit";
|
||||
|
||||
@ -430,6 +429,7 @@ export default abstract class Chart<T extends Schema> {
|
||||
? `${this.name}:${date}:${span}:${group}`
|
||||
: `${this.name}:${date}:${span}`;
|
||||
|
||||
const { getChartInsertLock } = await import("@/misc/app-lock.js");
|
||||
const unlock = await getChartInsertLock(lockKey);
|
||||
try {
|
||||
// ロック内でもう1回チェックする
|
||||
|
Loading…
Reference in New Issue
Block a user