[evince/wip/hadess/faster-smb-pdfs: 2/2] shell: Don't copy whole files from remote shares




commit 6cb4a630d175ab813895629d7ede02bea3e40d8f
Author: Bastien Nocera <hadess hadess net>
Date:   Sun May 8 14:25:48 2022 +0200

    shell: Don't copy whole files from remote shares
    
    We don't need to copy whole files from non-local files unless we can't
    seek around the file easily, such as for files on HTTP(S) servers.
    
    Consider that files that can be accessed through FUSE can be seeked
    around and don't need caching.
    
    This makes loading large PDFs from a local Samba share instantaneous.

 shell/ev-window.c | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/shell/ev-window.c b/shell/ev-window.c
index e75c6b196..bed494e0c 100644
--- a/shell/ev-window.c
+++ b/shell/ev-window.c
@@ -2416,6 +2416,7 @@ ev_window_open_uri (EvWindow       *ev_window,
 {
        EvWindowPrivate *priv = GET_PRIVATE (ev_window);
        GFile *source_file;
+       g_autofree char *path = NULL;
 
        priv->in_reload = FALSE;
 
@@ -2440,13 +2441,19 @@ ev_window_open_uri (EvWindow       *ev_window,
 
        priv->window_mode = mode;
 
+       source_file = g_file_new_for_uri (uri);
+
        g_clear_pointer (&priv->uri, g_free);
-       priv->uri = g_strdup (uri);
+       path = g_file_get_path (source_file);
+       /* Try to use FUSE-backed files if possible to avoid downloading */
+       if (path)
+               priv->uri = g_filename_to_uri (path, NULL, NULL);
+       else
+               priv->uri = g_strdup (uri);
 
        g_clear_object (&priv->metadata);
        g_clear_object (&priv->bookmarks);
 
-       source_file = g_file_new_for_uri (uri);
        if (ev_is_metadata_supported_for_file (source_file)) {
                priv->metadata = ev_metadata_new (source_file);
                ev_window_init_metadata_with_default_values (ev_window);
@@ -2473,13 +2480,13 @@ ev_window_open_uri (EvWindow       *ev_window,
        setup_size_from_metadata (ev_window);
        setup_model_from_metadata (ev_window);
 
-       priv->load_job = ev_job_load_new (uri);
+       priv->load_job = ev_job_load_new (priv->uri);
        g_signal_connect (priv->load_job,
                          "finished",
                          G_CALLBACK (ev_window_load_job_cb),
                          ev_window);
 
-       if (!g_file_is_native (source_file) && !priv->local_uri) {
+       if (path == NULL && !priv->local_uri) {
                ev_window_load_file_remote (ev_window, source_file);
        } else {
                ev_window_show_loading_message (ev_window);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]