From d1eff5692b8da32b75822d4a6fec8c1d81f1170b Mon Sep 17 00:00:00 2001 From: Max Gaukler Date: Thu, 7 Mar 2024 20:45:25 +0100 Subject: [PATCH] To avoid freezes, don't check if recent files exist Inkscape checked if recent files exist, to clean up the recent files menu and the command palette. Furthermore, for the command palette the modification date of files was queried. However, this could lead to "freezes" where Inkscape got stuck for 30 seconds or even more. These freezes occured at startup or when opening the command palette. Therefore, all these file operations are removed. Background: Any stat() operation can take very long if the file path refers to an inaccessible drive (Windows: network drive with unreachable host, Linux: unplugged USB drive with automount, nonexistent host with afuse,...). Fixes https://gitlab.com/inkscape/inkscape/-/issues/2348 --- src/ui/desktop/menubar.cpp | 3 +- src/ui/dialog/command-palette.cpp | 54 ++++++++++++------------------- src/ui/dialog/startup.cpp | 4 +-- 3 files changed, 24 insertions(+), 37 deletions(-) diff --git a/src/ui/desktop/menubar.cpp b/src/ui/desktop/menubar.cpp index 51893685f0..4520e633a4 100644 --- a/src/ui/desktop/menubar.cpp +++ b/src/ui/desktop/menubar.cpp @@ -161,8 +161,7 @@ build_menu() #endif ; - // this is potentially expensive: local FS access (remote files are not checked) - valid_file = valid_file && recent_file->exists(); + // Note: Do not check if the file exists, to avoid long delays. See https://gitlab.com/inkscape/inkscape/-/issues/2348 . if (!valid_file) { continue; diff --git a/src/ui/dialog/command-palette.cpp b/src/ui/dialog/command-palette.cpp index 357b3bb5c9..dbbef1a83e 100644 --- a/src/ui/dialog/command-palette.cpp +++ b/src/ui/dialog/command-palette.cpp @@ -119,7 +119,7 @@ CommandPalette::CommandPalette() recent_file->has_application("inkscape") or recent_file->has_application("inkscape.exe"); - valid_file = valid_file and recent_file->exists(); + // Note: Do not check if the file exists, to avoid long delays. See https://gitlab.com/inkscape/inkscape/-/issues/2348 . if (not valid_file) { continue; @@ -213,43 +213,31 @@ void CommandPalette::append_recent_file_operation(const Glib::ustring &path, boo auto &CPDescription (get_widget (operation_builder, "CPDescription")); const auto file = Gio::File::create_for_path(path); - if (file->query_exists()) { - const Glib::ustring file_name = file->get_basename(); + const Glib::ustring file_name = file->get_basename(); - if (is_import) { - // Used for Activate row signal of listbox and not - CPGroup.set_text("import"); - CPActionFullLabel.set_text("import"); // For filtering only + if (is_import) { + // Used for Activate row signal of listbox and not + CPGroup.set_text("import"); + CPActionFullLabel.set_text("import"); // For filtering only - } else { - CPGroup.set_text("open"); - CPActionFullLabel.set_text("open"); // For filtering only - } + } else { + CPGroup.set_text("open"); + CPActionFullLabel.set_text("open"); // For filtering only + } - // Hide for recent_file, not required - CPActionFullButton.set_visible(false); + // Hide for recent_file, not required + CPActionFullButton.set_visible(false); - CPName.set_text((is_import ? _("Import") : _("Open")) + (": " + file_name)); - CPName.set_tooltip_text((is_import ? ("Import") : ("Open")) + (": " + file_name)); // Tooltip_text are not translatable - CPDescription.set_text(path); - CPDescription.set_tooltip_text(path); + CPName.set_text((is_import ? _("Import") : _("Open")) + (": " + file_name)); + CPName.set_tooltip_text((is_import ? ("Import") : ("Open")) + (": " + file_name)); // Tooltip_text are not translatable + CPDescription.set_text(path); + CPDescription.set_tooltip_text(path); - { - Glib::DateTime mod_time; -#if GLIBMM_CHECK_VERSION(2, 62, 0) - mod_time = file->query_info()->get_modification_date_time(); - // Using this to reduce instead of ActionFullName widget because fullname is searched -#else - mod_time.create_now_local(file->query_info()->modification_time()); -#endif - CPShortcut.set_text(mod_time.format("%d %b %R")); - } - // Add to suggestions - if (is_suggestion) { - _CPSuggestions.append(CPOperation); - } else { - _CPHistory.append(CPOperation); - } + // Add to suggestions + if (is_suggestion) { + _CPSuggestions.append(CPOperation); + } else { + _CPHistory.append(CPOperation); } } diff --git a/src/ui/dialog/startup.cpp b/src/ui/dialog/startup.cpp index cb39918cc3..7fad62ca77 100644 --- a/src/ui/dialog/startup.cpp +++ b/src/ui/dialog/startup.cpp @@ -341,8 +341,8 @@ StartScreen::enlist_recent_files() // This uri is a GVFS uri, so parse it with that or it will fail. auto file = Gio::File::create_for_uri(item->get_uri()); std::string path = file->get_path(); - if (!path.empty() && Glib::file_test(path, Glib::FileTest::IS_REGULAR) - && item->get_mime_type() == "image/svg+xml") { + // Note: Do not check if the file exists, to avoid long delays. See https://gitlab.com/inkscape/inkscape/-/issues/2348 . + if (!path.empty() && item->get_mime_type() == "image/svg+xml") { Gtk::TreeModel::Row row = *(store->append()); row[cols.col_name] = item->get_display_name(); row[cols.col_id] = item->get_uri(); -- GitLab