gravitystorm left a comment (openstreetmap/openstreetmap-website#6379)

I'm not very good with database locks, but I have two questions:

```ruby
changeset = Changeset.lock.find(params[:changeset_id])
```

Is this different from `changeset = 
Changeset.find(params[:changeset_id]).lock!` ? As far as I can tell from the 
docs, it's the same thing, but we use the `.lock!` variant elsewhere. If they 
are indeed identical, then I'd prefer to use the `.lock!` variant here, since 
that makes slightly easier to understand that it's the changeset being locked, 
and not e.g. the whole `Changeset` table.

Second question, in #6366 the "safe navigation operator" was used, e.g. 
`node.changeset&.lock!`. I found that surprising, since taking a lock is 
generally not optional! Is this deliberate, or is it a side-effect of taking 
the lock too early on e.g. should the lock be taken after the code that 
validates the changeset exists? Or is there something else there about locks 
that I don't understand?

-- 
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/pull/6379#issuecomment-3382454762
You are receiving this because you are subscribed to this thread.

Message ID: 
<openstreetmap/openstreetmap-website/pull/6379/[email protected]>
_______________________________________________
rails-dev mailing list
[email protected]
https://lists.openstreetmap.org/listinfo/rails-dev

Reply via email to