Fixed performance bug

This commit is contained in:
Ahmed Salah Tawfik Ibrahim 2023-11-15 18:14:57 +01:00
parent 03d2b0cdf9
commit 6cf162bb91
1 changed files with 106 additions and 106 deletions

View File

@ -594,7 +594,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (result){
_log.info("Wrote user post with id " + post.getKey());
}
closeSession(session);
return result;
}
@ -642,7 +642,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
if (result){
_log.info("Wrote user post with id " + post.getKey());
}
closeSession(session);
return result;
}
@ -732,7 +732,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean result = session.execute(writeBatch).wasApplied();
if (result)
_log.info("Wrote app post with id " + post.getKey());
closeSession(session);
return result;
}
/**
@ -780,7 +780,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean result = session.execute(writeBatch).wasApplied();
if (result)
_log.info("Wrote app post with id " + post.getKey());
closeSession(session);
return result;
}
/**
@ -842,10 +842,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
PreparedStatement stmt3 = createVreTimelineEntry(session);
writeBatch.add(stmt3.bind(vreid, toCheck.getTime().toInstant(), UUID.fromString(toCheck.getKey())));
closeSession(session);
try{
boolean res = session.execute(writeBatch).wasApplied();
closeSession(session);
return res;
}catch (Exception e) {
e.printStackTrace();
@ -871,10 +871,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
PreparedStatement stmt3 = createVreTimelineEntry(session);
writeBatch.add(stmt3.bind(vreid, toCheck.getTime().toInstant(), UUID.fromString(toCheck.getKey())));
closeSession(session);
try{
boolean res = session.execute(writeBatch).wasApplied();
closeSession(session);
return res;
}catch (Exception e) {
e.printStackTrace();
@ -893,10 +893,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Feed post;
try{
post = findFeedById(feedid, session).get();
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
return null;
}
return post;
@ -912,10 +912,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Post post;
try{
post = findPostById(postid, session).get();
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
return null;
}
return post;
@ -939,7 +939,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.isEqualTo(QueryBuilder.bindMarker())
.build());
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e) {
e.printStackTrace();
}
@ -986,7 +986,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.isEqualTo(QueryBuilder.bindMarker())
.build());
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e) {
e.printStackTrace();
}
@ -1030,10 +1030,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
_log.error("Delete Post ERROR for postid " + feedId);
closeSession(session);
return false;
}
_log.info("Delete Post OK");
@ -1053,10 +1053,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
_log.error("Delete Post ERROR for postid " + postid);
closeSession(session);
return false;
}
_log.info("Delete Post OK");
@ -1221,10 +1221,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1253,10 +1253,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1289,10 +1289,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
for (Row row: result.all()){
if (row.getUuid(POST_ID).toString().equals(postid)){
@ -1320,10 +1320,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(appid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1352,10 +1352,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(appid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1387,10 +1387,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(PrivacyLevel.PORTAL.toString()));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
for (Row row: result.all()) {
Feed toAdd = readFeedFromRow(row);
@ -1412,10 +1412,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(PrivacyLevel.PORTAL.toString()));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
for (Row row: result.all()) {
Post toAdd = readPostFromRow(row);
@ -1637,10 +1637,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(vreid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1669,10 +1669,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(vreid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
List<String> toReturn = result.all().stream().map(row-> {
@ -1723,7 +1723,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
writeBatch.add(stmt3.bind(n.getUserid(), n.getTime().toInstant(), UUID.fromString(n.getKey())));
try{
boolean res = session.execute(writeBatch).wasApplied();
closeSession(session);
return res;
}catch (Exception e){
e.printStackTrace();
@ -1740,11 +1740,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
CqlSession session = conn.getKeyspaceSession();
try {
toReturn = findNotById(notificationid, session).get();
closeSession(session);
}
catch (Exception e) {
e.printStackTrace();
closeSession(session);
}
return toReturn;
}
@ -1769,7 +1769,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
// execute the operations
try {
boolean res = session.execute(writeBatch).wasApplied();
closeSession(session);
return res;
} catch (Exception e) {
_log.error("ERROR while setting Notification " + notificationidToSet + " to read.");
@ -1791,10 +1791,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
ArrayList<String> toReturn = new ArrayList<String>();
@ -1820,10 +1820,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
ArrayList<String> toReturn = new ArrayList<String>();
@ -2020,10 +2020,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean res = false;
try{
res = session.execute(writeBatch).wasApplied();
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
if (res) {
@ -2081,10 +2081,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
//if there are no settings for this user create an entry and put all of them at true
@ -2166,7 +2166,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
e.printStackTrace();
return false;
@ -2190,15 +2190,13 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(UUID.fromString(commentId)));
closeSession(session);
if (result.all().isEmpty()) {
throw new CommentIDNotFoundException("The requested commentId: " + commentId + " is not existing");
}
toReturn = readCommentFromRow(result.one());
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
return toReturn;
@ -2220,20 +2218,22 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
List<Comment> toReturn = new ArrayList<Comment>();
ResultSet result = null;
CqlSession session = conn.getKeyspaceSession();
PreparedStatement stmtFind = session.prepare(QueryBuilder
PreparedStatement stmtFind = session.prepare("SELECT * FROM comments WHERE postid=?");
/*PreparedStatement stmtFind = session.prepare(QueryBuilder
.selectFrom(COMMENTS).all()
.where
.whereColumn(POST_ID).isEqualTo(QueryBuilder.bindMarker())
.build());
.build());*/
try {
result = session.execute(stmtFind.bind(UUID.fromString(postid)));
closeSession(session);
for (Row row : result.all()) {
Comment toAdd = readCommentFromRow(row);
toReturn.add(toAdd);
}
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
return toReturn;
@ -2283,7 +2283,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind());
closeSession(session);
if (!result.all().isEmpty()){
result.all().parallelStream().forEach( row->{
@ -2303,7 +2303,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
}
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
if(sort)
@ -2325,11 +2325,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
boolean res = session.execute(writeBatch).wasApplied();
closeSession(session);
_log.info("Comments update OK to: " + comment2Edit.getText());
return res;
} catch (Exception e) {
closeSession(session);
_log.error("Comments update NOT OK ");
return false;
}
@ -2350,9 +2350,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
closeSession(session);
_log.error("Comment Delete FAILED for " + commentid + " from Feed " + feedid);
e.printStackTrace();
}
@ -2403,7 +2403,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
UUID.fromString(like.getFeedid())));
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
e.printStackTrace();
return false;
@ -2426,9 +2426,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.add(deleteUserLikeEntry(session).bind(userid, UUID.fromString(likeid)));
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
closeSession(session);
_log.error("Like Delete FAILED for " + likeid + " from Feed " + feedid);
e.printStackTrace();
}
@ -2459,10 +2459,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(userid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
ArrayList<String> toReturn = new ArrayList<String>();
@ -2652,10 +2652,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Like toAdd = readLikeFromRow(row);
toReturn.add(toAdd);
}
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
return toReturn;
}
@ -2681,11 +2681,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
if (! (firstInsert && secondInsert)) {
_log.error("saveHashTags: Could not save the hashtag(s)");
closeSession(session);
return false;
}
}
closeSession(session);
return true;
}
/**
@ -2705,12 +2705,12 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
if (! (firstDelete && secondInsert)) {
_log.error("deleteHashTags: Could not delete the hashtag(s)");
closeSession(session);
return false;
}
}
closeSession(session);
return true;
}
/**
@ -2732,11 +2732,11 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, true);
if (! (firstInsert && secondInsert)) {
_log.error("saveHashTags: Could not save the hashtag(s)");
closeSession(session);
return false;
}
}
closeSession(session);
return true;
}
/**
@ -2757,16 +2757,16 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
boolean secondInsert = updateVREHashtagCount(vreid, lowerCaseHashtag, false);
if (!(firstDelete && secondInsert)) {
_log.error("deleteHashTags: Could not delete the hashtag(s)");
closeSession(session);
return false;
}
}else{
_log.error("deleteHashTags: Could not delete the hashtag(s)");
closeSession(session);
return false;
}
}
closeSession(session);
return true;
}
/**
@ -2784,10 +2784,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(vreid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
@ -2816,10 +2816,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(vreid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
HashMap<String, Integer> toReturn = new HashMap<String, Integer> ();
@ -2876,7 +2876,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
resultPost = session.execute(stmtFind1.bind(hashtag));
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
PreparedStatement stmtFind2 = session.prepare(QueryBuilder
@ -2889,7 +2889,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
resultComment = session.execute(stmtFind2.bind(hashtag));
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
Set<String> postIds = new HashSet<>();
@ -2930,7 +2930,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
resultPost = session.execute(stmtFind1.bind(hashtag));
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
PreparedStatement stmtFind2 = session.prepare(QueryBuilder
@ -2943,7 +2943,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
resultComment = session.execute(stmtFind2.bind(hashtag));
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
Set<String> postIds = new HashSet<>();
@ -3013,7 +3013,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
result = session.execute(stmtFind1.bind(email));
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
// Iterate rows and their columns
@ -3047,7 +3047,7 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
//an entry in the EMAIL Invites
m.add(createNewEmailInviteEntry(session).bind(email, invite.getVreid(), UUID.fromString(invite.getKey())));
boolean result = session.execute(m).wasApplied();
closeSession(session);
return result ? InviteOperationResult.SUCCESS : InviteOperationResult.FAILED;
}
/**
@ -3069,10 +3069,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
throw new InviteStatusNotFoundException("The requested inviteid: " + inviteid + " is not existing");
}
toReturn = readAInviteFromRow(result.one());
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
return toReturn;
}
@ -3109,10 +3109,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.add(updateVreInviteEntry(session, STATUS).bind(status.toString(), vreid, UUID.fromString(inviteid)));
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
_log.error("ERROR while setting Invite " + inviteid + " to " + status.toString());
closeSession(session);
return false;
}
_log.trace("Invite Status Set to " + status.toString() + " OK");
@ -3132,10 +3132,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.bind(vreid));
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
ArrayList<String> invitesIds = new ArrayList<String>();
@ -3183,10 +3183,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
Attachment toAdd = readAttachmentFromRow(row);
toReturn.add(toAdd);
}
closeSession(session);
} catch (Exception e) {
e.printStackTrace();
closeSession(session);
return null;
}
return toReturn;
@ -3222,9 +3222,9 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
toSave.getThumbnailURL(),
toSave.getMimeType()
));
closeSession(session);
} catch (Exception e) {
closeSession(session);
e.printStackTrace();
return false;
}
@ -3517,10 +3517,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
//an entry in the feed CF
try {
session.execute(updatePostEntry(session, COMMENTS_NO).bind((long) newCount, UUID.fromString(toUpdate.getKey())));
closeSession(session);
} catch (Exception e) {
_log.error("CommentsNo update NOT OK ");
closeSession(session);
return false;
}
_log.info("CommentsNo update OK to: " + newCount);
@ -3546,10 +3546,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
//an entry in the feed CF
try {
session.execute(updatePostEntry(session, LIKES_NO).bind((long)newCount, UUID.fromString(toUpdate.getKey())));
closeSession(session);
} catch (Exception e) {
_log.error("LikesNo update NOT OK ");
closeSession(session);
return false;
}
_log.info("LikesNo update OK to: " + newCount);
@ -3599,10 +3599,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
try {
session.execute(writeBatch);
closeSession(session);
} catch (Exception e) {
_log.error("Hashtag Count update NOT OK ");
closeSession(session);
return false;
}
_log.debug("Hashtag Count update OK to: " + newCount);
@ -3638,10 +3638,10 @@ public final class DBCassandraAstyanaxImpl implements DatabookStore {
.build());
try {
result = session.execute(stmtFind.getQuery());
closeSession(session);
} catch (Exception e){
e.printStackTrace();
closeSession(session);
}
for (Row row : result.all()) {