From 2cc6efba8c7adb0841119bf5349623dc56eca8fc Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Tue, 3 May 2016 14:24:50 -0400 Subject: [PATCH] FIX: Featuring topics wasn't happy with concurrency. --- app/models/category_featured_topic.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/models/category_featured_topic.rb b/app/models/category_featured_topic.rb index c408bb46505..4f3404ab26b 100644 --- a/app/models/category_featured_topic.rb +++ b/app/models/category_featured_topic.rb @@ -40,7 +40,11 @@ class CategoryFeaturedTopic < ActiveRecord::Base CategoryFeaturedTopic.delete_all(category_id: c.id) if results results.each_with_index do |topic_id, idx| - c.category_featured_topics.create(topic_id: topic_id, rank: idx) + begin + c.category_featured_topics.create(topic_id: topic_id, rank: idx) + rescue PG::UniqueViolation + # If another process features this topic, just ignore it + end end end end