-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: avoiding IDs override while creating conturrent runtime notifica…
…tions
- Loading branch information
1 parent
6167139
commit fedafca
Showing
5 changed files
with
50 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
import { EntityManager } from 'typeorm' | ||
import { NextEntityId } from '../model' | ||
import { AnyEntity, Constructor, EntityManagerOverlay } from './overlay' | ||
|
||
// used to retrieve the next id for an entity | ||
export async function getNextIdForEntity(em: EntityManager, entityName: string): Promise<number> { | ||
// used to retrieve the next id for an entity from NextEntityId table using either EntityManager or Overlay | ||
export async function getNextIdForEntity( | ||
store: EntityManager | EntityManagerOverlay, | ||
entityName: string | ||
): Promise<string | undefined> { | ||
// Get next entity id from overlay (this will mostly be used in the mappings context) | ||
if (store instanceof EntityManagerOverlay) { | ||
const row = await store | ||
.getRepository(NextEntityId as Constructor<NextEntityId & AnyEntity>) | ||
.getOneBy({ entityName: entityName }) | ||
|
||
const id = row?.nextId.toString() | ||
|
||
// Update the id to be the next one in the overlay | ||
if (row) { | ||
row.nextId++ | ||
} | ||
|
||
return id | ||
} | ||
|
||
// Get next entity id from EntityManager (this will mostly be used in the graphql-server/auth-api context) | ||
let row: NextEntityId | null | ||
if (process.env.TESTING === 'true' || process.env.TESTING === '1') { | ||
row = await em.getRepository(NextEntityId).findOne({ | ||
row = await store.getRepository(NextEntityId).findOne({ | ||
where: { entityName }, | ||
}) | ||
} else { | ||
row = await em.getRepository(NextEntityId).findOne({ | ||
row = await store.getRepository(NextEntityId).findOne({ | ||
where: { entityName }, | ||
lock: { mode: 'pessimistic_write' }, | ||
}) | ||
} | ||
const id = parseInt(row?.nextId.toString() || '1') | ||
const id = row?.nextId.toString() | ||
return id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,5 @@ | ||
export { | ||
addNotification, | ||
defaultNotificationPreferences, | ||
preferencesForNotification, | ||
addNotification, | ||
} from './helpers' | ||
// export * from './notificationTexts' | ||
// export * from './notificationLinks' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters