Ticket #14175: 0001-text_search-avoid-flooding-messages-while-searching.patch

File 0001-text_search-avoid-flooding-messages-while-searching.patch, 2.3 KB (added by phoudoin, 17 months ago)
  • src/apps/text_search/Grepper.cpp

    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()  
    170170    BMessage message;
    171171    char fileName[B_PATH_NAME_LENGTH*2];
    172172    int count = 0;
     173    bigtime_t lastProgressReportTime = 0, now;
    173174
    174175    printf("paths_writer started.\n");
    175176
    176177    while (!fMustQuit && fIterator->GetNextName(fileName)) {
    177178
    178         message.MakeEmpty();
    179         message.what = MSG_REPORT_FILE_NAME;
    180         message.AddString("filename", fileName);
    181 
    182179        BEntry entry(fileName);
    183180        entry_ref ref;
    184181        entry.GetRef(&ref);
    185182        if (!entry.Exists()) {
    186183            if (fIterator->NotifyNegatives()) {
     184                message.MakeEmpty();
    187185                message.what = MSG_REPORT_RESULT;
     186                message.AddString("filename", fileName);
    188187                message.AddRef("ref", &ref);
    189188                fTarget.SendMessage(&message);
    190189            }
    Grepper::_WriterThread()  
    202201            continue;
    203202        }
    204203
     204        count++;
     205
    205206        // file exists, send it to xargs
    206207        write(fXargsInput, fileName, strlen(fileName));
    207208        write(fXargsInput, "\n", 1);
    208209        // printf(">>>>>> %s\n", fileName);
    209210
    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        }
    213222    }
    214223
    215224    write(fXargsInput, kEOFTag, strlen(kEOFTag));
    Grepper::_WriterThread()  
    218227
    219228    printf("paths_writer stopped (%d paths).\n", count);
    220229
     230
    221231    return 0;
    222232}
    223233