Duplicate post numbers within a topic


(PJH) #1

We have a thread with duplicate post IDs. Described in detail here:

Essentially the post numbers in the referenced thread (link goes to 2726) go

  • 2726
  • 2727
  • 2828
  • 2828
  • 2829
  • 2930

No idea how it came about, it’s clearly not reproducible, and was only observed after someone noticed the post count didn’t quite match the green counter.


(Jeff Atwood) #2

Looking at the timestamps, they are different though:

###2828 (1)

<span class="relative-date" title="July 5, 2014 12:10pm" data-time="1404587420799" data-format="tiny">5 Jul</span>

###2828 (2)

<span class="relative-date" title="July 5, 2014 12:10pm" data-time="1404587420798" data-format="tiny">5 Jul</span>

Not sure how two post IDs can collide like that, but I see it.


(PJH) #3

Given the closeness of those data-times, I’m guessing some sort of race condition…


(Sam Saffron) #4

Its not post id that is colliding though, that is not possible. Its the post_number. Let me review the code to ensure a unique index is on topic_id, post_number.


(Kane York) #5

Yes, they have the same post numbers, but different (and sequential!) post IDs (unique across whole forum), as you can see here:

http://what.thedailywtf.com/posts/25181/cooked.json
http://what.thedailywtf.com/posts/25182/cooked.json


(Sam Saffron) #6

This should not be possible … I need to get my SQL karate belt out though for the renumbering query… its not easy.


(PJH) #7

Another instance - two posts #21’s. (Lounge, so admin access required.)


(Sam Saffron) #8

More than that

discourse=# select topic_id, post_number, count(*) from posts
discourse-# group by topic_id, post_number 
discourse-# having count(*) > 1;
 topic_id | post_number | count 
----------+-------------+-------
     1475 |          21 |     2
      285 |          38 |     2
     1008 |         118 |     2
     1000 |        2728 |     2
      759 |         220 |     2
      532 |          21 |     2
     1053 |           2 |     2
(7 rows)

(Sam Saffron) #9

This is fixed now:

https://github.com/discourse/discourse/commit/1b03feacf8e7deb325bf85dd7c21964a7075feea


(Sam Saffron) #10