Skip to content
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

Persist attributes before save #2

Merged
merged 1 commit into from
Oct 4, 2018
Merged

Conversation

finalwharf
Copy link

@finalwharf finalwharf commented Oct 1, 2018

What does this PR do?

  • Allow a user to specify when to persist vault attributes.

Where should the reviewer start?

  • lib/vault/encrypted_model.rb

Any background context you want to provide?

  • Persisting Vault attributes on an after_save uses two separate queries:
    one for the model INSERT/UPDATE, and another to UPDATE the ciphertext
    for the encrypted attributes. Encrypting the attributes with a before_save
    avoids the second query. In some cases users might not want to have two
    queries when saving a single record. This would be necessary for example,
    when one has an auditing table and/or stored procedures that take some action
    when a record is changed.

/cc @popovm

Copy link
Member

@popovm popovm left a comment

Choose a reason for hiding this comment

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

LGTM 🥇

@finalwharf finalwharf force-pushed the master branch 2 times, most recently from b816bff to 54b6047 Compare October 4, 2018 07:58
@finalwharf finalwharf force-pushed the persist_before_save branch from 3889fa1 to 8fc83e2 Compare October 4, 2018 08:11
Persisting Vault attributes on an `after_save` uses two separate queries:
one for the model `INSERT/UPDATE`, and another to `UPDATE` the ciphertext
for the encrypted attributes. Encrypting the attributes with a `before_save`
avoids the second query. In some cases users might _not_ want to have two
queries when saving a single record. This would be necessary for example,
when one has an auditing table and/or stored procedures that take some action
when a record is changed.
@finalwharf finalwharf force-pushed the persist_before_save branch from 8fc83e2 to ba2de1f Compare October 4, 2018 09:40
@finalwharf
Copy link
Author

@popovm @bliof The requested changes were addressed. Please review again.

Copy link
Member

@popovm popovm left a comment

Choose a reason for hiding this comment

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

Fine with me 👍

@finalwharf finalwharf merged commit 95a1243 into master Oct 4, 2018
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.

3 participants