Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't repeat deserialization of decomposed queries in getQuery() #163

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions luwak/src/main/java/uk/co/flax/luwak/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,10 @@ public MonitorQuery getQuery(final String queryId) throws IOException {
throw new IllegalStateException("Cannot call getQuery() as queries are not stored");
final MonitorQuery[] queryHolder = new MonitorQuery[]{ null };
queryIndex.search(new TermQuery(new Term(FIELDS.id, queryId)), (id, query, dataValues) -> {
BytesRef serializedMQ = dataValues.mq.get(dataValues.doc);
queryHolder[0] = MonitorQuery.deserialize(serializedMQ);
if (queryHolder[0] == null) {
BytesRef serializedMQ = dataValues.mq.get(dataValues.doc);
queryHolder[0] = MonitorQuery.deserialize(serializedMQ);
}
});
return queryHolder[0];
}
Expand Down
4 changes: 2 additions & 2 deletions luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ public void canDeleteById() throws IOException, UpdateException {
@Test
public void canRetrieveQuery() throws IOException, UpdateException {

monitor.update(new MonitorQuery("query1", "this"), new MonitorQuery("query2", "that"));
monitor.update(new MonitorQuery("query1", "this"), new MonitorQuery("query2", "that other"));
Assertions.assertThat(monitor.getQueryCount()).isEqualTo(2);
Assertions.assertThat(monitor.getQueryIds()).contains("query1", "query2");

MonitorQuery mq = monitor.getQuery("query2");
Assertions.assertThat(mq).isEqualTo(new MonitorQuery("query2", "that"));
Assertions.assertThat(mq).isEqualTo(new MonitorQuery("query2", "that other"));

}

Expand Down