ignore duplicate queries

This commit is contained in:
Zoltan Haindrich 2024-08-06 14:20:42 +00:00
parent 19fe5867b1
commit 3f507d8648
1 changed files with 8 additions and 0 deletions

View File

@ -30,12 +30,15 @@ import java.io.UnsupportedEncodingException;
import java.net.URI; import java.net.URI;
import java.nio.charset.StandardCharsets; import java.nio.charset.StandardCharsets;
import java.util.Date; import java.util.Date;
import java.util.HashSet;
import java.util.Set;
public class QuidemRecorder implements AutoCloseable, DruidHook<String> public class QuidemRecorder implements AutoCloseable, DruidHook<String>
{ {
private PrintStream printStream; private PrintStream printStream;
private File file; private File file;
private DruidHookDispatcher hookDispatcher; private DruidHookDispatcher hookDispatcher;
private Set<String> queries = new HashSet<>();
public QuidemRecorder(URI quidemURI, DruidHookDispatcher hookDispatcher, File file) public QuidemRecorder(URI quidemURI, DruidHookDispatcher hookDispatcher, File file)
{ {
@ -67,11 +70,16 @@ public class QuidemRecorder implements AutoCloseable, DruidHook<String>
public synchronized void invoke(HookKey<String> key, String query) public synchronized void invoke(HookKey<String> key, String query)
{ {
if (DruidHook.SQL.equals(key)) { if (DruidHook.SQL.equals(key)) {
if (queries.contains(query)) {
// ignore duplicate queries
return;
}
printStream.println("# " + new Date()); printStream.println("# " + new Date());
printStream.print(query); printStream.print(query);
printStream.println(";"); printStream.println(";");
printStream.println("!ok"); printStream.println("!ok");
printStream.flush(); printStream.flush();
queries.add(query);
return; return;
} }
} }