Skip to content

Commit

Permalink
Improve MAM logging; #servers-384
Browse files Browse the repository at this point in the history
  • Loading branch information
woj-tek committed Sep 27, 2022
1 parent e177471 commit 30d9022
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/main/java/tigase/archive/QueryCriteria.java
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,18 @@ public List<Element> getItems() {
}
return items;
}

@Override
public String toString() {
final StringBuffer sb = new StringBuffer("QueryCriteria{");
sb.append("QueryImpl='").append(super.toString()).append('\'');
sb.append(", contains=").append(contains);
sb.append(", tags=").append(tags);
sb.append(", collections=").append(collections);
sb.append(", items=").append(items.size());
sb.append(", useMessageIdInRsm=").append(useMessageIdInRsm);
sb.append(", fasteningCollation=").append(getFasteningCollation());
sb.append('}');
return sb.toString();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ public String getStableId(BareJID owner, BareJID buddy, String stanzaId) throws
@Override
public void queryCollections(Q crit, CollectionHandler<Q, MessageArchiveRepository.Collection> collectionHandler) throws TigaseDBException {
try {
log.log(Level.FINEST, () -> "Querying collections: crit: " + crit);
Integer count = getCollectionsCount(crit);
if (count == null) {
count = 0;
Expand All @@ -179,6 +180,7 @@ public void queryCollections(Q crit, CollectionHandler<Q, MessageArchiveReposito
public void queryItems(Q crit, ItemHandler<Q, MAMRepository.Item> itemHandler)
throws TigaseDBException, ComponentException {
try {
log.log(Level.FINEST, () -> "Querying items, criteria: " + crit);
if (!crit.getIds().isEmpty()) {
ArrayDeque<MAMRepository.Item> items = new ArrayDeque<>();
for (String id : crit.getIds()) {
Expand Down Expand Up @@ -444,6 +446,7 @@ protected int setQueryParams(PreparedStatement stmt, Q crit, FasteningCollation
}
stmt.setString(i++, sb.toString());
}
log.log(Level.FINEST, () -> "Setting PS parameters: " + stmt + ", crit: " + crit);
return i;
}

Expand All @@ -456,6 +459,7 @@ protected Item newItemInstance() {
}

private void getCollectionsItems(Q crit, CollectionHandler<Q, MessageArchiveRepository.Collection> collectionHandler) throws SQLException {
log.log(Level.FINEST, () -> "Getting collections items: " + crit);
ResultSet selectRs = null;
BareJID owner = crit.getQuestionerJID().getBareJID();
PreparedStatement get_collections_st = data_repo.getPreparedStatement(owner, GET_COLLECTIONS_QUERY);
Expand Down Expand Up @@ -486,6 +490,7 @@ private void getCollectionsItems(Q crit, CollectionHandler<Q, MessageArchiveRepo
}

private Integer getCollectionsCount(Q crit) throws SQLException {
log.log(Level.FINEST, () -> "Getting collections: " + crit);
ResultSet countRs = null;
Integer count = null;
BareJID owner = crit.getQuestionerJID().getBareJID();
Expand Down Expand Up @@ -513,6 +518,7 @@ private Integer getColletionPosition(String uid, Q query) {
}

private MAMRepository.Item getItem(Q crit, String itemId) throws SQLException {
log.log(Level.FINEST, () -> "Getting MAM item: " + crit + ", itemId: " + itemId);
ResultSet rs = null;
BareJID owner = crit.getQuestionerJID().getBareJID();
PreparedStatement get_message_st = data_repo.getPreparedStatement(owner, GET_MESSAGE_QUERY);
Expand Down Expand Up @@ -546,6 +552,7 @@ private void getItemsItems(Q crit, Range range, ItemHandler<Q, MAMRepository.Ite
Queue<Item> results = new ArrayDeque<Item>();
BareJID owner = crit.getQuestionerJID().getBareJID();

log.log(Level.FINEST, () -> "Getting items items, criteria: " + crit + ", range: " + range);
// there is no point to execute query if limit is estimated to be 0
if (Math.min(range.size(), crit.getRsm().getMax()) > 0) {
PreparedStatement get_messages_st = data_repo.getPreparedStatement(owner, GET_MESSAGES_QUERY);
Expand Down Expand Up @@ -598,6 +605,7 @@ private void getItemsItems(Q crit, Range range, ItemHandler<Q, MAMRepository.Ite
}

private Integer getItemsCount(Q crit) throws SQLException {
log.log(Level.FINEST, () -> "Getting items count, criteria: " + crit);
Integer count = null;
ResultSet rs = null;
BareJID owner = crit.getQuestionerJID().getBareJID();
Expand All @@ -618,6 +626,7 @@ private Integer getItemsCount(Q crit) throws SQLException {
}

private Integer getItemPosition(String uid, Q query) throws SQLException, ComponentException {
log.log(Level.FINEST, () -> "Getting item position, criteria: " + query + ", uid: " + uid);
if (uid == null || uid.isEmpty()) {
return null;
}
Expand Down

0 comments on commit 30d9022

Please sign in to comment.