-
Notifications
You must be signed in to change notification settings - Fork 289
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: import events without id field #15452
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #15452 +/- ##
==========================================
+ Coverage 43.32% 43.38% +0.06%
==========================================
Files 647 647
Lines 21831 21833 +2
Branches 5018 5019 +1
==========================================
+ Hits 9458 9473 +15
+ Misses 11154 11134 -20
- Partials 1219 1226 +7 |
src/script/backup/BackupService.ts
Outdated
): 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 => id !== undefined); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If you want to ensure that if is a string, why don't you check for it instead of undefined?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah it's either undefined
or string
in this case so doesn't really matter, but I find your idea more readable, just updated it ;)
* fix: import events without id field * refactor: CR suggestion
Regression introduced in #15085
There are some types of events like
conversation.member-join
orconversation.member-leave
that do not contain"id"
."id"
field was typed as mandatory, while it was not true for mentioned types of events.table.where('id').anyOf(ids).toArray()
was throwing error when the list ofids
contained at least oneundefined
value.The fix is to type id as optional and filter out the events that do not contain id.