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

Fix updating a record twice in one session #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

kadivadavidak
Copy link

When updating a record a second (or more) time(s) in the same session, the changes are not being saved to the fulltext search. It seems that the changes get cached the first time, and don't get updated on the fulltext model. Performing the refresh reloads the model from the DB. This will be slightly less efficient due to the DB access a second time, but it is probably worth the slight inefficiency to have expected behavior when updating your models.

Steps to replicate:

  1. Open tinker
  2. Update a model that uses Indexable
  3. View record in fulltext DB table to verify record updated
  4. In same tinker session make another update to same model record
  5. View record in DB again to verify that record did NOT update

Restarting tinker in between updates does not result in the inconsistency.

When updating a record a second (or more) time(s) in the same session, the changes are not being saved to the fulltext search. It seems that the changes get cached the first time, and don't get updated on the fulltext model. Performing the refresh reloads the model from the DB. This will be slightly less efficient due to the DB access a second time, but it is probably worth the slight inefficiency to have expected behavior when updating your models.

Steps to replicate:
1. Open tinker
2. Update a model that uses Indexable
3. View record in fulltext DB table to verify record updated
4. In same tinker session make another update to same model record
5. View record in DB again to verify that record did NOT update

Restarting tinker in between updates does not result in the inconsistency.
@bbrala
Copy link
Member

bbrala commented Aug 8, 2018

Thanks for the contribution, i agree this tradeoff is worth it. Thing is though, refresh isn't available in Laravel before 5.5, perhaps $this->fresh() is a better option?

@kadivadavidak
Copy link
Author

I believe I tested $this->fresh() and ran into some issue with it. I cannot remember exactly what it was, but it seems that it should work in place of $this->refresh.

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