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);
}
// 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();
topic.cache.size = 45