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:
Nick Burch
2011-08-15 16:44:47 +00:00
parent f7e691b593
commit 4f59c0b4eb
3 changed files with 63 additions and 1 deletions

View File

@@ -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());
@@ -499,6 +500,41 @@ public class DiscussionServiceImpl implements DiscussionService
String postName = children.get(0).getQName().getLocalName(); String postName = children.get(0).getQName().getLocalName();
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

View File

@@ -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
@@ -288,6 +290,10 @@ public class DiscussionServiceImplTest
// Topic will now have a primary post // Topic will now have a primary post
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
@@ -355,6 +361,15 @@ public class DiscussionServiceImplTest
assertNotNull(objects); assertNotNull(objects);
assertEquals(topic.getNodeRef(), objects.getFirst().getNodeRef()); assertEquals(topic.getNodeRef(), objects.getFirst().getNodeRef());
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

View File

@@ -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