From 5ba7a82f730ad6b0a3fb89c1e9bee12854191a81 Mon Sep 17 00:00:00 2001 From: Marvin Justice Date: Tue, 6 Mar 2018 10:57:03 -0500 Subject: [PATCH] Don't repeat deserialization of decomposed queries in getQuery() --- luwak/src/main/java/uk/co/flax/luwak/Monitor.java | 6 ++++-- luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/luwak/src/main/java/uk/co/flax/luwak/Monitor.java b/luwak/src/main/java/uk/co/flax/luwak/Monitor.java index e0af334f4..9c0de89f1 100644 --- a/luwak/src/main/java/uk/co/flax/luwak/Monitor.java +++ b/luwak/src/main/java/uk/co/flax/luwak/Monitor.java @@ -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]; } diff --git a/luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java b/luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java index e18d1f7d7..303fd4785 100644 --- a/luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java +++ b/luwak/src/test/java/uk/co/flax/luwak/TestMonitor.java @@ -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")); }