Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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: upsert identity when creating keys in dashboard #2111
base: main
Are you sure you want to change the base?
fix: upsert identity when creating keys in dashboard #2111
Changes from 7 commits
aef29c2
caf3f87
db49abd
fd7369c
fe706b7
ed476fd
bece6ec
37dd148
b3797a4
b4f9273
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
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.
🛠️ Refactor suggestion
Optimize
upsertIdentity
to avoid unnecessary database queriesCurrently, if the identity does not exist, you insert it and then perform another query to retrieve the identity. This results in two database calls. You can optimize this by using the result of the insert operation or by using an
UPSERT
that returns the updated or inserted row if your database supports it.Modify the
upsertIdentity
function to return the identity directly from the insert operation:This change eliminates the need for a second query, improving the efficiency of the function.
Also applies to: 178-185
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.
Use
new Date()
instead ofDate.now()
for consistent date objectsIn your code, you're using
Date.now()
to setcreatedAt
andupdatedAt
, which returns a timestamp number. However, elsewhere in your code, such as in line 96~, you usenew Date()
, which returns aDate
object. This inconsistency can lead to issues if the database expects aDate
object rather than a timestamp.Apply this diff to fix the inconsistency:
And in the
onDuplicateKeyUpdate
block:Also applies to: 168-168
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.
Ensure consistent handling of the
meta
fieldIn the
identities
table insertion,meta
is set to an empty object{}
. In contrast, when inserting into thekeys
table (line 96~),meta
is serialized usingJSON.stringify
. To maintain consistency and prevent potential issues with data storage and retrieval, ensure thatmeta
is handled the same way in both cases.Consider serializing
meta
when inserting into theidentities
table:Or, if the database schema for
identities.meta
accepts JSON objects directly, ensure that this is consistently handled across your codebase.📝 Committable suggestion