{"action":"created","issue":{"url":"https://api.github.com/repos/swanandp/acts_as_list/issues/254","repository_url":"https://api.github.com/repos/swanandp/acts_as_list","labels_url":"https://api.github.com/repos/swanandp/acts_as_list/issues/254/labels{/name}","comments_url":"https://api.github.com/repos/swanandp/acts_as_list/issues/254/comments","events_url":"https://api.github.com/repos/swanandp/acts_as_list/issues/254/events","html_url":"https://github.com/swanandp/acts_as_list/issues/254","id":207779582,"number":254,"title":"Positions are repeating when creating items concurrently","user":{"login":"ProGM","id":5167659,"avatar_url":"https://avatars.githubusercontent.com/u/5167659?v=3","gravatar_id":"","url":"https://api.github.com/users/ProGM","html_url":"https://github.com/ProGM","followers_url":"https://api.github.com/users/ProGM/followers","following_url":"https://api.github.com/users/ProGM/following{/other_user}","gists_url":"https://api.github.com/users/ProGM/gists{/gist_id}","starred_url":"https://api.github.com/users/ProGM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProGM/subscriptions","organizations_url":"https://api.github.com/users/ProGM/orgs","repos_url":"https://api.github.com/users/ProGM/repos","events_url":"https://api.github.com/users/ProGM/events{/privacy}","received_events_url":"https://api.github.com/users/ProGM/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":5,"created_at":"2017-02-15T11:35:45Z","updated_at":"2017-02-16T17:43:08Z","closed_at":null,"body":"I'm using Rails 5.0.1 and acts_as_list v0.8.2 and postgresql.\r\n\r\nWhen creating items in a list concurrently (like in concurrent xhr requests), positions gets repeating.\r\n\r\nI tried to replicate in console:\r\n\r\n```ruby\r\nclass Paragraph < ApplicationRecord\r\n  belongs_to :article\r\n  acts_as_list scope: :article\r\nend\r\n\r\nclass Article < ApplicationRecord\r\n  has_many :paragraphs\r\nend\r\n```\r\n\r\n```ruby\r\na = Article.create!\r\np = Array.new(5) { Paragraph.new(article: a) }\r\nt = p.map { |e| Thread.new { e.save! } }\r\nt.map(&:join)\r\na.reload.pluck(:position) # => [1, 1, 1, 1, 1]\r\n```\r\n\r\nI've temporarily set an unique index for [:article_id, :position] to fail when this happens, but it's really a big problem for me."},"comment":{"url":"https://api.github.com/repos/swanandp/acts_as_list/issues/comments/280403736","html_url":"https://github.com/swanandp/acts_as_list/issues/254#issuecomment-280403736","issue_url":"https://api.github.com/repos/swanandp/acts_as_list/issues/254","id":280403736,"user":{"login":"ProGM","id":5167659,"avatar_url":"https://avatars.githubusercontent.com/u/5167659?v=3","gravatar_id":"","url":"https://api.github.com/users/ProGM","html_url":"https://github.com/ProGM","followers_url":"https://api.github.com/users/ProGM/followers","following_url":"https://api.github.com/users/ProGM/following{/other_user}","gists_url":"https://api.github.com/users/ProGM/gists{/gist_id}","starred_url":"https://api.github.com/users/ProGM/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ProGM/subscriptions","organizations_url":"https://api.github.com/users/ProGM/orgs","repos_url":"https://api.github.com/users/ProGM/repos","events_url":"https://api.github.com/users/ProGM/events{/privacy}","received_events_url":"https://api.github.com/users/ProGM/received_events","type":"User","site_admin":false},"created_at":"2017-02-16T17:43:08Z","updated_at":"2017-02-16T17:43:08Z","body":"@brendon @swanandp I confirm that using a lock on the article solves the issue. 👍 \r\n\r\nI'm not sure of it, but... shouldn't this be something that the gem could manage itself?\r\nI mean, it's pretty common to add elements to a list in a concurrent environment (in my case, I'm using the `puma` web server, that manages requests using threads).\r\n\r\nOtherwise, if this is not something that the gem deals with, you should put a few line about this in the docs or the README, I think :)\r\n"}}
{"actor":{"display_login":"ProGM"}}