Skip to content

Refactor Event creation to avoid two DB writes when creating Event with disavowal#7301

Merged
mitchellhenke merged 4 commits intomainfrom
mitchellhenke/save-an-update-on-events
Nov 7, 2022
Merged

Refactor Event creation to avoid two DB writes when creating Event with disavowal#7301
mitchellhenke merged 4 commits intomainfrom
mitchellhenke/save-an-update-on-events

Conversation

@mitchellhenke
Copy link
Contributor

🛠 Summary of changes

Instead of creating an event and then updating a column, we can save one database write by creating the event with all of the columns at the beginning.

Copy link
Contributor

@zachmargolis zachmargolis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! awesome win

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i think rubocop will request a trailing comma?

Suggested change
disavowal_token: disavowal_token
disavowal_token: disavowal_token,

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

possibly same?

Suggested change
disavowal_token: disavowal_token
disavowal_token: disavowal_token,

Comment on lines 33 to 34
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe could consider switching to keyword args and just inlining?

Suggested change
disavowal_token = SecureRandom.urlsafe_base64(32)
create_user_event(event_type, user, disavowal_token)
create_user_event(event_type, user, disavowal_token: SecureRandom.urlsafe_base64(32))

@mitchellhenke mitchellhenke force-pushed the mitchellhenke/save-an-update-on-events branch 3 times, most recently from 66736bf to a111151 Compare November 6, 2022 18:20
…th disavowal

changelog: Internal, Database, Refactor Event creation to avoid two DB writes when creating Event with disavowal
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/save-an-update-on-events branch from a111151 to e6d2736 Compare November 7, 2022 14:13
Comment on lines +107 to +108
event.disavowal_token = disavowal_token
event
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a bigger refactor than is good for this PR, but what if we removed the transient disavowal_token plaintext attribute and just returned it separately? ex

Suggested change
event.disavowal_token = disavowal_token
event
[event, disavowal_token]

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that makes sense to tackle following this, yeah

Copy link
Contributor Author

@mitchellhenke mitchellhenke Nov 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's also kind of a mess and could probably stand to be refactored again.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Had some bandwidth, gave it a shot in #7305

Mitchell Henke and others added 3 commits November 7, 2022 10:58
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
Co-authored-by: Zach Margolis <zachmargolis@users.noreply.github.com>
@mitchellhenke mitchellhenke force-pushed the mitchellhenke/save-an-update-on-events branch from 9efc309 to e756cf5 Compare November 7, 2022 17:54
@mitchellhenke mitchellhenke merged commit 32a0969 into main Nov 7, 2022
@mitchellhenke mitchellhenke deleted the mitchellhenke/save-an-update-on-events branch November 7, 2022 18:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants