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

Stale data overwrites good data if object has been updated since it was loaded #19

Open
joeyAghion opened this issue Sep 9, 2015 · 1 comment
Labels

Comments

@joeyAghion
Copy link

In the simplest case, imagine 2 jobs or requests are updating different fields of the same document.

  • Processes A and B both load the document into memory
  • Process A updates field :a and calls as_json (at this point, the cache is accurate)
  • Process B updates field :b and calls as_json (at this point, a stale value of :a replaced the accurate value)

Or, in a console:

j1 = User.find_by_email('[email protected]')
# => #<User ...>
j2 = User.find_by_email('[email protected]')
# => #<User ...>
j1.phone
# => "646-338-3382"
j1.as_json(properties: :all)[:phone]
# => "646-338-3382"
j2.phone
# => "646-338-3382"
j2.phone = '800-foo-barz'
# => "800-foo-barz"
j2.save!
# => true
j2.as_json(properties: :all)[:phone]
# => "800-foo-barz"
j1.profession = 'chimney sweep'
# => "chimney sweep"
j1.save!
# => true
j1.as_json(properties: :all)[:phone]
# => "646-338-3382"
User.find_by_email('[email protected]').as_json(properties: :all)[:phone]
# => "646-338-3382"
User.find_by_email('[email protected]').phone
# => "800-foo-barz"
@acjay
Copy link

acjay commented Sep 9, 2015

Is the core issue here that as_json is meant to be a read method, but it also mutates shared state and can't be done atomically?

@dblock dblock added bug bug? and removed bug labels Mar 11, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants