Skip to content

Commit

Permalink
fix: import events without id field (#15452) (#15454)
Browse files Browse the repository at this point in the history
* fix: import events without id field

* refactor: CR suggestion

Co-authored-by: Patryk Górka <patrykbunix@gmail.com>
  • Loading branch information
thisisamir98 and PatrykBuniX committed Jul 12, 2023
1 parent 920972a commit 78597e2
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions src/script/backup/BackupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ export class BackupService {
{
generatePrimaryKey,
generateId,
}: {generatePrimaryKey?: (entry: T) => string; generateId?: (entry: T) => string} = {},
}: {generatePrimaryKey?: (entry: T) => string; generateId?: (entry: T) => string | undefined} = {},
): Promise<number> {
if (this.storageService.db) {
const table = await this.storageService.db.table(tableName);
Expand Down Expand Up @@ -112,14 +112,14 @@ export class BackupService {
private async addByIds<T>(
table: Dexie.Table<T, unknown>,
entities: T[],
generateId?: (entry: T) => string,
generateId?: (entry: T) => string | undefined,
): Promise<number> {
if (!generateId) {
await table.bulkAdd(entities);
return entities.length;
}

const ids = entities.map(generateId);
const ids = entities.map(generateId).filter((id): id is string => typeof id === 'string');
const existingEntities = await table.where('id').anyOf(ids).toArray();
const newEntities = entities.filter(
entity => !existingEntities.some(existingEntity => generateId(existingEntity) === generateId(entity)),
Expand Down
2 changes: 1 addition & 1 deletion src/script/storage/record/EventRecord.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export type StoredEvent<T> = {
/** Only used with IndexedDB table 'event' */
primary_key: string;
category: number;
id: string;
id?: string;
/** if the message is ephemeral, that's the amount of time it should be displayed to the user
* the different types are
* - string: a datestring
Expand Down

0 comments on commit 78597e2

Please sign in to comment.