mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-08-07 17:49:17 +00:00
ALF-9153 Avoid fetching too much un-used data when rendering a Discussions Topic to JSON with the reply count
git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@29773 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -477,7 +477,8 @@ public class DiscussionServiceImpl implements DiscussionService
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PostInfo getPrimaryPost(TopicInfo topic) {
|
public PostInfo getPrimaryPost(TopicInfo topic)
|
||||||
|
{
|
||||||
// First up, see if there is a post with the same name as the topic
|
// First up, see if there is a post with the same name as the topic
|
||||||
// (That's the normal Share case)
|
// (That's the normal Share case)
|
||||||
PostInfo post = getPost(topic, topic.getSystemName());
|
PostInfo post = getPost(topic, topic.getSystemName());
|
||||||
@@ -500,6 +501,41 @@ public class DiscussionServiceImpl implements DiscussionService
|
|||||||
return buildPost(postNodeRef, topic, postName, null);
|
return buildPost(postNodeRef, topic, postName, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PostInfo getMostRecentPost(TopicInfo topic)
|
||||||
|
{
|
||||||
|
// Do a listing at the Node level, ordered by created date
|
||||||
|
// to get the most recent nodes
|
||||||
|
NodeBackedEntity node = null;
|
||||||
|
int skip = 0;
|
||||||
|
int pageSize = 10000;
|
||||||
|
while(node == null)
|
||||||
|
{
|
||||||
|
PagingRequest paging = new PagingRequest(skip, pageSize);
|
||||||
|
paging.setRequestTotalCountMax(skip+pageSize+10);
|
||||||
|
CannedQueryResults<NodeBackedEntity> results =
|
||||||
|
listEntries(topic.getNodeRef(), ForumModel.TYPE_POST, null, paging);
|
||||||
|
|
||||||
|
// Move to the next page if we're not at the end
|
||||||
|
if(results.hasMoreItems())
|
||||||
|
{
|
||||||
|
skip += pageSize;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
// Bail if the topic lacks posts
|
||||||
|
if(results.getPage().size() == 0)
|
||||||
|
{
|
||||||
|
// No posts in the topic
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
// Grab the last node
|
||||||
|
node = results.getPage().get(results.getPage().size()-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wrap and return
|
||||||
|
return buildPost(node.getNodeRef(), topic, node.getName(), null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PagingResults<TopicInfo> listTopics(String siteShortName,
|
public PagingResults<TopicInfo> listTopics(String siteShortName,
|
||||||
|
@@ -246,6 +246,8 @@ public class DiscussionServiceImplTest
|
|||||||
|
|
||||||
// The topic has no primary post
|
// The topic has no primary post
|
||||||
assertEquals(null, DISCUSSION_SERVICE.getPrimaryPost(topic));
|
assertEquals(null, DISCUSSION_SERVICE.getPrimaryPost(topic));
|
||||||
|
// Which means no recent post
|
||||||
|
assertEquals(null, DISCUSSION_SERVICE.getMostRecentPost(topic));
|
||||||
|
|
||||||
|
|
||||||
// Get with an arbitrary name gives nothing
|
// Get with an arbitrary name gives nothing
|
||||||
@@ -289,6 +291,10 @@ public class DiscussionServiceImplTest
|
|||||||
assertNotNull(DISCUSSION_SERVICE.getPrimaryPost(topic));
|
assertNotNull(DISCUSSION_SERVICE.getPrimaryPost(topic));
|
||||||
assertEquals(post.getNodeRef(), DISCUSSION_SERVICE.getPrimaryPost(topic).getNodeRef());
|
assertEquals(post.getNodeRef(), DISCUSSION_SERVICE.getPrimaryPost(topic).getNodeRef());
|
||||||
|
|
||||||
|
// The new post will be the most recent one
|
||||||
|
assertNotNull(DISCUSSION_SERVICE.getMostRecentPost(topic));
|
||||||
|
assertEquals(post.getNodeRef(), DISCUSSION_SERVICE.getMostRecentPost(topic).getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
// Topic will now have one post listed
|
// Topic will now have one post listed
|
||||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||||
@@ -357,6 +363,15 @@ public class DiscussionServiceImplTest
|
|||||||
assertEquals(reply1.getNodeRef(), objects.getSecond().getNodeRef());
|
assertEquals(reply1.getNodeRef(), objects.getSecond().getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
|
// The primary post will be unchanged
|
||||||
|
assertNotNull(DISCUSSION_SERVICE.getPrimaryPost(topic));
|
||||||
|
assertEquals(post.getNodeRef(), DISCUSSION_SERVICE.getPrimaryPost(topic).getNodeRef());
|
||||||
|
|
||||||
|
// But the most recent will be the newest reply
|
||||||
|
assertNotNull(DISCUSSION_SERVICE.getMostRecentPost(topic));
|
||||||
|
assertEquals(reply2.getNodeRef(), DISCUSSION_SERVICE.getMostRecentPost(topic).getNodeRef());
|
||||||
|
|
||||||
|
|
||||||
// Check the overall count now
|
// Check the overall count now
|
||||||
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
posts = DISCUSSION_SERVICE.listPosts(topic, new PagingRequest(10));
|
||||||
assertEquals(3, posts.getPage().size());
|
assertEquals(3, posts.getPage().size());
|
||||||
|
@@ -124,6 +124,17 @@ public interface DiscussionService {
|
|||||||
@NotAuditable
|
@NotAuditable
|
||||||
PostInfo getPrimaryPost(TopicInfo topic);
|
PostInfo getPrimaryPost(TopicInfo topic);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the newest (most recent) Post in a topic, be that
|
||||||
|
* the Primary Post or a Reply.
|
||||||
|
* This is typically used when identifying if a topic has had
|
||||||
|
* new posts added to it since the user last saw it.
|
||||||
|
* Note that this works on Created Date, and not Modified/Updated,
|
||||||
|
* so edits to an existing post will not change this.
|
||||||
|
*/
|
||||||
|
@NotAuditable
|
||||||
|
PostInfo getMostRecentPost(TopicInfo topic);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves an existing {@link TopicInfo} from the repository,
|
* Retrieves an existing {@link TopicInfo} from the repository,
|
||||||
* which is within a site
|
* which is within a site
|
||||||
|
Reference in New Issue
Block a user