diff options
author | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-08 22:55:14 +0200 |
---|---|---|
committer | TheArcaneBrony <myrainbowdash949@gmail.com> | 2022-08-09 23:28:27 +0200 |
commit | ee01a689e255bcf8775387b3d5e4e8a6577908a3 (patch) | |
tree | c4af8a9baf8bd349bded7e7b6b7e4c8329a75f37 | |
parent | Fix accidental edit in benchmark (diff) | |
download | server-ee01a689e255bcf8775387b3d5e4e8a6577908a3.tar.xz |
rename initDatabase to clarify function
-rw-r--r-- | api/src/Server.ts | 4 | ||||
-rw-r--r-- | cdn/src/Server.ts | 4 | ||||
-rw-r--r-- | gateway/src/Server.ts | 4 | ||||
-rw-r--r-- | gateway/src/opcodes/LazyRequest.ts | 4 | ||||
-rw-r--r-- | util/src/util/Database.ts | 2 |
5 files changed, 9 insertions, 9 deletions
diff --git a/api/src/Server.ts b/api/src/Server.ts index f309834b..136f9814 100644 --- a/api/src/Server.ts +++ b/api/src/Server.ts @@ -1,6 +1,6 @@ import { Server, ServerOptions } from "lambert-server"; import { Authentication, CORS } from "./middlewares/"; -import { Config, initDatabase, initEvent, registerRoutes } from "@fosscord/util"; +import { Config, getOrInitialiseDatabase, initEvent, registerRoutes } from "@fosscord/util"; import { ErrorHandler } from "./middlewares/ErrorHandler"; import { BodyParser } from "./middlewares/BodyParser"; import { Router, Request, Response, NextFunction } from "express"; @@ -32,7 +32,7 @@ export class FosscordServer extends Server { } async start() { - await initDatabase(); + await getOrInitialiseDatabase(); await Config.init(); await initEvent(); await initInstance(); diff --git a/cdn/src/Server.ts b/cdn/src/Server.ts index b8d71fa9..b27d3321 100644 --- a/cdn/src/Server.ts +++ b/cdn/src/Server.ts @@ -1,5 +1,5 @@ import { Server, ServerOptions } from "lambert-server"; -import { Config, initDatabase, registerRoutes } from "@fosscord/util"; +import { Config, getOrInitialiseDatabase, registerRoutes } from "@fosscord/util"; import path from "path"; import avatarsRoute from "./routes/avatars"; import iconsRoute from "./routes/role-icons"; @@ -15,7 +15,7 @@ export class CDNServer extends Server { } async start() { - await initDatabase(); + await getOrInitialiseDatabase(); await Config.init(); this.app.use((req, res, next) => { res.set("Access-Control-Allow-Origin", "*"); diff --git a/gateway/src/Server.ts b/gateway/src/Server.ts index 254820c9..82fbeba2 100644 --- a/gateway/src/Server.ts +++ b/gateway/src/Server.ts @@ -1,6 +1,6 @@ import dotenv from "dotenv"; dotenv.config(); -import { closeDatabase, Config, initDatabase, initEvent } from "@fosscord/util"; +import { closeDatabase, Config, getOrInitialiseDatabase, initEvent } from "@fosscord/util"; import ws from "ws"; import { Connection } from "./events/Connection"; import http from "http"; @@ -46,7 +46,7 @@ export class Server { } async start(): Promise<void> { - await initDatabase(); + await getOrInitialiseDatabase(); await Config.init(); await initEvent(); if (!this.server.listening) { diff --git a/gateway/src/opcodes/LazyRequest.ts b/gateway/src/opcodes/LazyRequest.ts index 0dbdb526..5ba65cdd 100644 --- a/gateway/src/opcodes/LazyRequest.ts +++ b/gateway/src/opcodes/LazyRequest.ts @@ -1,4 +1,4 @@ -import { getPermission, listenEvent, Member, Role, initDatabase } from "@fosscord/util"; +import { getPermission, listenEvent, Member, Role, getOrInitialiseDatabase } from "@fosscord/util"; import { LazyRequest } from "../schema/LazyRequest"; import { Send } from "../util/Send"; import { OPCODES } from "../util/Constants"; @@ -17,7 +17,7 @@ async function getMembers(guild_id: string, range: [number, number]) { // TODO: wait for typeorm to implement ordering for .find queries https://github.com/typeorm/typeorm/issues/2620 // TODO: rewrite this, released in 0.3.0 - let members = await (await initDatabase()).getRepository(Member) + let members = await (await getOrInitialiseDatabase()).getRepository(Member) .createQueryBuilder("member") .where("member.guild_id = :guild_id", { guild_id }) .leftJoinAndSelect("member.roles", "role") diff --git a/util/src/util/Database.ts b/util/src/util/Database.ts index d0d39f4c..84ce473d 100644 --- a/util/src/util/Database.ts +++ b/util/src/util/Database.ts @@ -15,7 +15,7 @@ import { config } from "dotenv"; let promise: Promise<any>; let dataSource: DataSource; -export async function initDatabase(): Promise<DataSource> { +export async function getOrInitialiseDatabase(): Promise<DataSource> { //if (dataSource) return dataSource; // prevent initalizing multiple times if(dataSource.isInitialized) return dataSource; |