From 5988ac387cd81253a310a95f7475b39bbd6e620a Mon Sep 17 00:00:00 2001
From: Philippe Houdoin <philipp.houdoin@gmail.com>
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.
---
src/apps/text_search/Grepper.cpp | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/src/apps/text_search/Grepper.cpp b/src/apps/text_search/Grepper.cpp
index 025fb5ed8a..114d803295 100644
a
|
b
|
Grepper::_WriterThread()
|
170 | 170 | BMessage message; |
171 | 171 | char fileName[B_PATH_NAME_LENGTH*2]; |
172 | 172 | int count = 0; |
| 173 | bigtime_t lastProgressReportTime = 0, now; |
173 | 174 | |
174 | 175 | printf("paths_writer started.\n"); |
175 | 176 | |
176 | 177 | while (!fMustQuit && fIterator->GetNextName(fileName)) { |
177 | 178 | |
178 | | message.MakeEmpty(); |
179 | | message.what = MSG_REPORT_FILE_NAME; |
180 | | message.AddString("filename", fileName); |
181 | | |
182 | 179 | BEntry entry(fileName); |
183 | 180 | entry_ref ref; |
184 | 181 | entry.GetRef(&ref); |
185 | 182 | if (!entry.Exists()) { |
186 | 183 | if (fIterator->NotifyNegatives()) { |
| 184 | message.MakeEmpty(); |
187 | 185 | message.what = MSG_REPORT_RESULT; |
| 186 | message.AddString("filename", fileName); |
188 | 187 | message.AddRef("ref", &ref); |
189 | 188 | fTarget.SendMessage(&message); |
190 | 189 | } |
… |
… |
Grepper::_WriterThread()
|
202 | 201 | continue; |
203 | 202 | } |
204 | 203 | |
| 204 | count++; |
| 205 | |
205 | 206 | // file exists, send it to xargs |
206 | 207 | write(fXargsInput, fileName, strlen(fileName)); |
207 | 208 | write(fXargsInput, "\n", 1); |
208 | 209 | // printf(">>>>>> %s\n", fileName); |
209 | 210 | |
210 | | fTarget.SendMessage(&message); |
211 | | |
212 | | count++; |
| 211 | now = system_time(); |
| 212 | // to avoid message flood, |
| 213 | // report progress no more than 20 times per second |
| 214 | if (now - lastProgressReportTime > 50000) { |
| 215 | message.MakeEmpty(); |
| 216 | message.what = MSG_REPORT_FILE_NAME; |
| 217 | message.AddString("filename", fileName); |
| 218 | // message.AddInt32("count", count); |
| 219 | fTarget.SendMessage(&message); |
| 220 | lastProgressReportTime = now; |
| 221 | } |
213 | 222 | } |
214 | 223 | |
215 | 224 | write(fXargsInput, kEOFTag, strlen(kEOFTag)); |
… |
… |
Grepper::_WriterThread()
|
218 | 227 | |
219 | 228 | printf("paths_writer stopped (%d paths).\n", count); |
220 | 229 | |
| 230 | |
221 | 231 | return 0; |
222 | 232 | } |
223 | 233 | |