Skip to content

Commit

Permalink
fix zombie idle db connections from within transactions (ToolJet#4072)
Browse files Browse the repository at this point in the history
  • Loading branch information
akshaysasidrn authored Sep 20, 2022
1 parent fb2540b commit 5108d12
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions server/src/services/app_import_export.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { AppVersion } from 'src/entities/app_version.entity';
import { GroupPermission } from 'src/entities/group_permission.entity';
import { AppGroupPermission } from 'src/entities/app_group_permission.entity';
import { DataSourcesService } from './data_sources.service';
import { dbTransactionWrap } from 'src/helpers/utils.helper';

@Injectable()
export class AppImportExportService {
Expand Down Expand Up @@ -66,13 +67,13 @@ export class AppImportExportService {

let importedApp: App;

await this.entityManager.transaction(async (manager) => {
await dbTransactionWrap(async (manager) => {
importedApp = await this.createImportedAppForUser(manager, appParams, user);
await this.buildImportedAppAssociations(manager, importedApp, appParams);
await this.createAdminGroupPermissions(manager, importedApp);
});

// FIXME: App slug updation callback doesnt work while wrapped in transaction
// NOTE: App slug updation callback doesnt work while wrapped in transaction
// hence updating slug explicitly
await importedApp.reload();
importedApp.slug = importedApp.id;
Expand All @@ -85,7 +86,7 @@ export class AppImportExportService {
const importedApp = manager.create(App, {
name: appParams.name,
organizationId: user.organizationId,
user: user,
userId: user.id,
slug: null, // Prevent db unique constraint error.
isPublic: false,
createdAt: new Date(),
Expand All @@ -107,7 +108,7 @@ export class AppImportExportService {
// create new app versions
for (const appVersion of appVersions) {
const version = manager.create(AppVersion, {
app: importedApp,
appId: importedApp.id,
definition: appVersion.definition,
name: appVersion.name,
createdAt: new Date(),
Expand Down Expand Up @@ -141,7 +142,7 @@ export class AppImportExportService {
appVersionId = appVersionMapping[appVersion.id];
}
const newSource = manager.create(DataSource, {
app: importedApp,
appId: importedApp.id,
name: source.name,
kind: source.kind,
appVersionId,
Expand All @@ -165,7 +166,7 @@ export class AppImportExportService {
}

const newQuery = manager.create(DataQuery, {
app: importedApp,
appId: importedApp.id,
name: query.name,
options: query.options,
kind: query.kind,
Expand Down

0 comments on commit 5108d12

Please sign in to comment.