From 7d1bfd62d4bc635cee451456d9936eae0173def1 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 23 Apr 2023 18:43:06 +0700 Subject: [PATCH] actually revert greplog update because it breaks stuff --- .../chomens_bot/plugins/GrepLogPlugin.java | 70 ++++++------------- 1 file changed, 23 insertions(+), 47 deletions(-) diff --git a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java index b9ff18fd..d6e92998 100644 --- a/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java +++ b/src/main/java/land/chipmunk/chayapak/chomens_bot/plugins/GrepLogPlugin.java @@ -10,10 +10,8 @@ import net.kyori.adventure.text.format.NamedTextColor; import java.io.*; import java.nio.charset.StandardCharsets; -import java.util.ArrayList; import java.util.Arrays; import java.util.Comparator; -import java.util.List; import java.util.regex.Pattern; import java.util.zip.GZIPInputStream; @@ -81,52 +79,30 @@ public class GrepLogPlugin { Arrays.sort(fileList, Comparator.comparing(File::getName)); // VERY IMPORTANT - // split the list into smaller chunks - int chunkSize = fileList.length / Runtime.getRuntime().availableProcessors(); - final List fileChunks = new ArrayList<>(); - for (int i = 0; i < fileList.length; i += chunkSize) { - int end = Math.min(i + chunkSize, fileList.length); - fileChunks.add(Arrays.copyOfRange(fileList, i, end)); - } + for (File file : fileList) { + final String fileName = file.getName(); + if (fileName.matches(".*\\.txt\\.gz")) { + try ( + FileInputStream fin = new FileInputStream(file); + GZIPInputStream gzin = new GZIPInputStream(fin, 65536); + BufferedReader br = new BufferedReader(new InputStreamReader(gzin, StandardCharsets.UTF_8)) + ) { + br.readLine(); + readFile(br); + } catch (Exception ignored) { + } // TODO: Handle exception + } else { + try ( + FileInputStream fin = new FileInputStream(file); + BufferedReader br = new BufferedReader(new InputStreamReader(fin, StandardCharsets.UTF_8)) + ) { + br.readLine(); + readFile(br); + } catch (Exception ignored) { + } // TODO: Handle exception + } - final List threads = new ArrayList<>(); - for (File[] chunk : fileChunks) { - final Thread thread = new Thread(() -> { - for (File file : chunk) { - final String fileName = file.getName(); - if (fileName.matches(".*\\.txt\\.gz")) { - try ( - FileInputStream fin = new FileInputStream(file); - GZIPInputStream gzin = new GZIPInputStream(fin, 65536); - BufferedReader br = new BufferedReader(new InputStreamReader(gzin, StandardCharsets.UTF_8)) - ) { - br.readLine(); - readFile(br); - } catch (Exception ignored) { - } // TODO: Handle exception - } else { - try ( - FileInputStream fin = new FileInputStream(file); - BufferedReader br = new BufferedReader(new InputStreamReader(fin, StandardCharsets.UTF_8)) - ) { - br.readLine(); - readFile(br); - } catch (Exception ignored) { - } // TODO: Handle exception - } - - if (queryStopped) break; - } - }); - thread.start(); - threads.add(thread); - } - - // wait for all of the threads to finish - for (Thread thread : threads) { - try { - thread.join(); - } catch (InterruptedException ignored) {} + if (queryStopped) break; } finish();