getRecentComments speeded up by reducing synchronization time at minimum

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-networking-library@130989 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Costantino Perciante 2016-08-06 06:19:53 +00:00
parent 59faa6b0d5
commit fbae17bb34
1 changed files with 28 additions and 19 deletions

View File

@ -1502,23 +1502,33 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.executeWithCallback(new RowCallback<String, String>() {
@Override
public void success(Rows<String, String> rows) {
synchronized (commentsByUser) {
nextRow: for (Row<String, String> row : rows) {
for(Column<String> column: row.getColumns())
if(column.getName().equals("Userid")){
if(column.getStringValue().equals(userid)){
try{
Comment c = readCommentById(row.getKey());
Feed f = readFeed(c.getFeedid());
if(c.getTime().getTime() >= timeInMillis &&
(f.getType() == FeedType.TWEET || f.getType() == FeedType.SHARE || f.getType() == FeedType.PUBLISH))
commentsByUser.add(c);
}catch(Exception e){
_log.error("Unable to read comment with id" + row.getKey(), e);
}
// use a temporary list for each thread
List<Comment> partialCommentsList = new ArrayList<Comment>();
nextRow: for (Row<String, String> row : rows) {
for(Column<String> column: row.getColumns()){
if(column.getName().equals("Userid")){
if(column.getStringValue().equals(userid)){
try{
Comment c = readCommentById(row.getKey());
Feed f = readFeed(c.getFeedid());
if(c.getTime().getTime() >= timeInMillis &&
(f.getType() == FeedType.TWEET || f.getType() == FeedType.SHARE || f.getType() == FeedType.PUBLISH))
partialCommentsList.add(c);
}catch(Exception e){
_log.error("Unable to read comment with id" + row.getKey(), e);
}
continue nextRow;
}
continue nextRow;
}
}
}
// if there is something to save...
if(partialCommentsList.size() > 0){
synchronized (commentsByUser){
commentsByUser.addAll(partialCommentsList);
}
}
}
@ -1528,12 +1538,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
// decrement value
int currentValue = maxRetryExecutions.decrementAndGet();
if(currentValue <= 0){
_log.error("Error while fetching user's recent comments ... repeating operation");
return true;
}else
{
_log.error("Too many errors while fetching user's comments, exiting");
return false;
}else{
_log.error("Error while fetching user's recent comments ... repeating operation");
return true;
}
}
});