On Thu, Feb 10, 2011 at 11:54 AM, Paul Bagwell <pba...@gmail.com> wrote: > I got models: > > - Post (id, thread_id, text, pid) > - Thread (id, name, last_pid) > > PID is the number of post in thread. So it needs to be unique to each > thread. Like: > Thread 1 : [1, 2, 3, 4, 5] > Thread 2 : [1, 2, 3, 4, 5, 6, 7] > > And the "last_pid" field of thread is cache of pid of last post in > post_set. > > How can last_pid update method be properly build? > Today I'm incrementing last_pid on each post creation and assigning > incremented value to new_post.pid.
Thats not going to scale. > The problem of this variant is: if many users post simultaneously, > some posts would have duplicate PIDs: > [1, 2, 3, 3, 2, 4, 5] > I don't know if this is a bug, but it can't be reproduced with built- > in-django http server, I only see it with apache or nginx. > Yep, hard to reproduce race conditions with a single process, single threaded web server. The easiest solution is to not do this. What purpose does it serve? If you wish to order the posts in the order in which they were made, simply record a created timestamp on the post model, and order them appropriately. If you wish to know the total number of posts in a thread, use aggregation to count them. Cheers Tom -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.