Skip to content

Commit

Permalink
Closing knex connections after using them in vite build.
Browse files Browse the repository at this point in the history
Vite build waits for all outstanding processes to finish, and database
connections appear to be something it considers outstanding, so it will
never end unless they are manually closed.
  • Loading branch information
barankyle committed Jun 15, 2023
1 parent 2c66cfc commit ba006f5
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 152 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/branch-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,5 @@ jobs:
timeout-minutes: 20
- run: npm run dev-docker
- run: npm run dev-reinit
- run: npm run test
- run: npm run build-client
- run: npm run test
142 changes: 8 additions & 134 deletions packages/client/scripts/getClientSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,142 +23,14 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { Type } from '@feathersjs/typebox'
import type { Static } from '@feathersjs/typebox'
import knex from 'knex'

export const clientSettingPath = 'client-setting'
import { clientDbToSchema } from '../../server-core/src/setting/client-setting/client-setting.resolvers'

export const clientSocialLinkSchema = Type.Object(
{
link: Type.String(),
icon: Type.String()
},
{ $id: 'ClientSocialLink', additionalProperties: false }
)
export type ClientSocialLinkType = Static<typeof clientSocialLinkSchema>

export const clientThemeOptionsSchema = Type.Object(
{
textColor: Type.String(),
navbarBackground: Type.String(),
sidebarBackground: Type.String(),
sidebarSelectedBackground: Type.String(),
mainBackground: Type.String(),
panelBackground: Type.String(),
panelCards: Type.String(),
panelCardHoverOutline: Type.String(),
panelCardIcon: Type.String(),
textHeading: Type.String(),
textSubheading: Type.String(),
textDescription: Type.String(),
iconButtonColor: Type.String(),
iconButtonHoverColor: Type.String(),
iconButtonBackground: Type.String(),
iconButtonSelectedBackground: Type.String(),
buttonOutlined: Type.String(),
buttonFilled: Type.String(),
buttonGradientStart: Type.String(),
buttonGradientEnd: Type.String(),
buttonTextColor: Type.String(),
scrollbarThumbXAxisStart: Type.String(),
scrollbarThumbXAxisEnd: Type.String(),
scrollbarThumbYAxisStart: Type.String(),
scrollbarThumbYAxisEnd: Type.String(),
scrollbarCorner: Type.String(),
inputOutline: Type.String(),
inputBackground: Type.String(),
primaryHighlight: Type.String(),
dropdownMenuBackground: Type.String(),
dropdownMenuHoverBackground: Type.String(),
dropdownMenuSelectedBackground: Type.String(),
drawerBackground: Type.String(),
popupBackground: Type.String(),
tableHeaderBackground: Type.String(),
tableCellBackground: Type.String(),
tableFooterBackground: Type.String(),
dockBackground: Type.String()
},
{ $id: 'ClientThemeOptions', additionalProperties: false }
)
export type ClientThemeOptionsType = Static<typeof clientThemeOptionsSchema>

// Main data model schema
export const clientSettingSchema = Type.Object(
{
id: Type.String({
format: 'uuid'
}),
logo: Type.String(),
title: Type.String(),
shortTitle: Type.String(),
startPath: Type.String(),
url: Type.String(),
releaseName: Type.String(),
siteDescription: Type.String(),
appleTouchIcon: Type.String(),
favicon32px: Type.String(),
favicon16px: Type.String(),
icon192px: Type.String(),
icon512px: Type.String(),
webmanifestLink: Type.String(),
swScriptLink: Type.String(),
appBackground: Type.String(),
appTitle: Type.String(),
appSubtitle: Type.String(),
appDescription: Type.String(),
appSocialLinks: Type.Array(Type.Ref(clientSocialLinkSchema)),
themeSettings: Type.Record(Type.String(), Type.Ref(clientThemeOptionsSchema)),
themeModes: Type.Record(Type.String(), Type.String()),
key8thWall: Type.String(),
homepageLinkButtonEnabled: Type.Boolean(),
homepageLinkButtonRedirect: Type.String(),
homepageLinkButtonText: Type.String(),
createdAt: Type.String({ format: 'date-time' }),
updatedAt: Type.String({ format: 'date-time' })
},
{ $id: 'ClientSetting', additionalProperties: false }
)
export type ClientSettingType = Static<typeof clientSettingSchema>

export type ClientSettingDatabaseType = Omit<ClientSettingType, 'appSocialLinks' | 'themeSettings' | 'themeModes'> & {
appSocialLinks: string
themeSettings: string
themeModes: string
}

export const clientDbToSchema = async (rawData: ClientSettingDatabaseType): Promise<ClientSettingType> => {
let appSocialLinks = JSON.parse(rawData.appSocialLinks) as ClientSocialLinkType[]

// Usually above JSON.parse should be enough. But since our pre-feathers 5 data
// was serialized multiple times, therefore we need to parse it twice.
if (typeof appSocialLinks === 'string') {
appSocialLinks = JSON.parse(appSocialLinks)
}

let themeSettings = JSON.parse(rawData.themeSettings) as Record<string, ClientThemeOptionsType>

// Usually above JSON.parse should be enough. But since our pre-feathers 5 data
// was serialized multiple times, therefore we need to parse it twice.
if (typeof themeSettings === 'string') {
themeSettings = JSON.parse(themeSettings)
}

let themeModes = JSON.parse(rawData.themeModes) as Record<string, string>

// Usually above JSON.parse should be enough. But since our pre-feathers 5 data
// was serialized multiple times, therefore we need to parse it twice.
if (typeof themeModes === 'string') {
themeModes = JSON.parse(themeModes)
}

return {
...rawData,
appSocialLinks,
themeSettings,
themeModes
}
}
const {
clientSettingPath,
ClientSettingDatabaseType
} = require('../../engine/src/schemas/setting/client-setting.schema')

export const getClientSetting = async () => {
const knexClient = knex({
Expand All @@ -175,7 +47,7 @@ export const getClientSetting = async () => {

const clientSetting = await knexClient
.select()
.from<ClientSettingDatabaseType>(clientSettingPath)
.from<typeof ClientSettingDatabaseType>(clientSettingPath)
.then(([dbClient]) => {
const dbClientConfig = clientDbToSchema(dbClient) || {
logo: './logo.svg',
Expand All @@ -197,5 +69,7 @@ export const getClientSetting = async () => {
console.warn(e)
})

await knexClient.destroy()

return clientSetting!
}
20 changes: 3 additions & 17 deletions packages/client/scripts/getCoilSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,9 @@ All portions of the code written by the Ethereal Engine team are Copyright © 20
Ethereal Engine. All Rights Reserved.
*/

import { Type } from '@feathersjs/typebox'
import type { Static } from '@feathersjs/typebox'
import knex from 'knex'

export const coilSettingPath = 'coil-setting'
export const coilSettingSchema = Type.Object(
{
id: Type.String({
format: 'uuid'
}),
paymentPointer: Type.String(),
clientId: Type.String(),
clientSecret: Type.String(),
createdAt: Type.String({ format: 'date-time' }),
updatedAt: Type.String({ format: 'date-time' })
},
{ $id: 'CoilSetting', additionalProperties: false }
)
export type CoilSettingType = Static<typeof coilSettingSchema>
import { coilSettingPath, CoilSettingType } from '../../engine/src/schemas/setting/coil-setting.schema'

export const getCoilSetting = async () => {
const knexClient = knex({
Expand Down Expand Up @@ -69,5 +53,7 @@ export const getCoilSetting = async () => {
console.warn(e)
})

await knexClient.destroy()

return coilSetting!
}

0 comments on commit ba006f5

Please sign in to comment.