[Logo] JForum - Powering Communities
  [Search] 搜尋   [Recent Topics] 最新主題   [Hottest Topics] 熱門主題   [Top Downloads] 熱門下載   [Groups] 回首頁 
[Register] 會員註冊 /  [Login] 登入 


JForum 2.8.3 is out with various fixes and improvements. Read all about it here

Topics by forum RSS feed
討論區首頁 » Developer Forum
發表人 內容
rostek


註冊時間: 2012/6/20
文章: 2
離線
Hi, I downloaded JForum and started changing it to my needs. First was making urls more friendly, now they contain info about post/topic title but it's not important. When I tested friendly urls with pagination, I saw results on subsequent pages do not appear. I looked at code and my question is, what sense is in this method:

public static List<Topic> topicsByForum(int forumId, int start)

{
TopicDAO tm = DataAccessDriver.getInstance().newTopicDAO();
int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
List<Topic> topics;

// Try to get the first's page of topics from the cache
if (SystemGlobals.getBoolValue(ConfigKeys.TOPIC_CACHE_ENABLED)) {
topics = TopicRepository.getTopics(forumId);

if (topics.isEmpty() || !TopicRepository.isLoaded(forumId)) {
synchronized (MUTEXT) {
if (topics.isEmpty() || !TopicRepository.isLoaded(forumId)) {
topics = tm.selectAllByForum(forumId);
TopicRepository.addAll(forumId, topics);
}
}
}
}
else {
topics = tm.selectAllByForumByLimit(forumId, start, topicsPerPage);
}

int size = topics.size();

while (size < start) {
start -= topicsPerPage;
}
if (start < 0) {
start = 0;
}

return topics.subList(start, (size < start + topicsPerPage) ? size : start + topicsPerPage);
}


in TopicsCommon class. What if in cache I have 20 results and go to records on 30th page? What is the subListing for, if I would not use cache and get exact list from database?

Thanks.
andowson


註冊時間: 2011/6/30
文章: 250
離線
TopicsCommon.topicsByForum(int forumId, int start) is used to fetch topics in forum forumId beginning from the index start.
For example:
TopicsCommon.topicsByForum(1, 0) returns topics start from index 0 in forum where forum_id=1.
How many topics returned is determined by topicsPerPage.

And if you enable cache of topics, JForum will look for them in the topic repository(cache) first. If the topic repository for the forum forumId is empty, JForum will load topics from database and cache it.
JForum try to load all the topics from database first, and then use subList to return only topicsPerPage line of records from the start index.

If topicsPerPage = 15, and you only have 20 topics in cache for the forum, the JForum will display the last 5 topics in the 2nd page.

If you disable cache of topics, JForum will fetch topics from the database directly. But only with limit number of records (topicsPerPage) returned.

rostek


註冊時間: 2012/6/20
文章: 2
離線
Thank you for the answer. Of course I understand the idea, but code does not do that.

// If the cache is full, remove the eldest element

int topicsPerPage = SystemGlobals.getIntValue(ConfigKeys.TOPICS_PER_PAGE);
if (!contains && forumTopicsList.size() + 1 > topicsPerPage) {
forumTopicsList.removeLast();


in TopicRepository:290, so cache can actually contain only ConfigKeys.TOPICS_PER_PAGE newest topics.
When you get topics = TopicRepository.getTopics(forumId); in TopicsCommon:101 you get newest topics from cache. How can you get topic for, for example start=1000?

andowson


註冊時間: 2011/6/30
文章: 250
離線
You are right. This is a bug.
The quick way to fix it is to remove this code fragment for checking with topicsPerPage limit.

I've committed a fix for it as revision 208.
The idea is to check if (start + topicsPerPage >= topicCacheSize) then reload the topics from database again.
topicCacheSize is a new configurable value in SystemGlobals.properties and the default value is 45:
topic.cache.size = 45

 
討論區首頁 » Developer Forum
前往:   
行動版
Powered by JForum 2.8.3 © 2023 JForum Team • Maintained by Andowson Chang and Ulf Dittmer