سؤال

I am working on a similar function that forum had, the number of pages in each forum section.

My thought and functions as follow:

  • A forum may have one or more than one section (sub-forum)
  • Each section may have zero or more than one thread
  • Each thread have an unique ID generated by Database (1,2,3...)
  • Each page may only display 15 threads
  • A section may have one or more than one pages.
  • Each thread may have one or more than one pages.

I have completed all the things except the last two things mentioned above. however, the number of pages has been a problem to me. Here's my thought:

  • Using Count(key) will definitely do the work, however , I am worried about the performance once the section has lots of threads.
  • Finding the last ID and divide it by 15 works too, however it will be inaccurate very soon.

Is there any possible solution to implement this function? Or is COUNT(key) is the best approach?

هل كانت مفيدة؟

المحلول

You could add a column to your thread table (something like 'postCount'), and then increment it whenever a post is added to that thread. Then you could use that value to determine the number of pages instead of counting the number of posts each time.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top