From 739e2ceffc6e9569c0f2a1b6bf39bb329ee2ba31 Mon Sep 17 00:00:00 2001 From: Philippe Houdoin Date: Thu, 7 Jun 2018 23:49:37 +0200 Subject: [PATCH] text_search: avoid flooding messages while searching. * This was making unresponsive the target window, making impossible to cancel it at all. Now the current filename is reported at 20Hz, well enough for good visual search progress feedback. Fixed #14175. Signed-off-by: Kacper Kasper Style fixes: * Commit message formatting. * Removed commented code and unnecessary whitespace. --- src/apps/text_search/Grepper.cpp | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/apps/text_search/Grepper.cpp b/src/apps/text_search/Grepper.cpp index 025fb5ed8a..95ac3c4ea7 100644 --- a/src/apps/text_search/Grepper.cpp +++ b/src/apps/text_search/Grepper.cpp @@ -170,21 +170,19 @@ Grepper::_WriterThread() BMessage message; char fileName[B_PATH_NAME_LENGTH*2]; int count = 0; + bigtime_t lastProgressReportTime = 0, now; printf("paths_writer started.\n"); while (!fMustQuit && fIterator->GetNextName(fileName)) { - - message.MakeEmpty(); - message.what = MSG_REPORT_FILE_NAME; - message.AddString("filename", fileName); - BEntry entry(fileName); entry_ref ref; entry.GetRef(&ref); if (!entry.Exists()) { if (fIterator->NotifyNegatives()) { + message.MakeEmpty(); message.what = MSG_REPORT_RESULT; + message.AddString("filename", fileName); message.AddRef("ref", &ref); fTarget.SendMessage(&message); } @@ -202,14 +200,22 @@ Grepper::_WriterThread() continue; } + count++; + // file exists, send it to xargs write(fXargsInput, fileName, strlen(fileName)); write(fXargsInput, "\n", 1); - // printf(">>>>>> %s\n", fileName); - fTarget.SendMessage(&message); - - count++; + now = system_time(); + // to avoid message flood, + // report progress no more than 20 times per second + if (now - lastProgressReportTime > 50000) { + message.MakeEmpty(); + message.what = MSG_REPORT_FILE_NAME; + message.AddString("filename", fileName); + fTarget.SendMessage(&message); + lastProgressReportTime = now; + } } write(fXargsInput, kEOFTag, strlen(kEOFTag));