After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 781032 - Simplify GdPdfLoader, improve caching, etc..
Simplify GdPdfLoader, improve caching, etc..
Status: RESOLVED FIXED
Product: gnome-documents
Classification: Core
Component: general
unspecified
Other All
: Normal normal
: ---
Assigned To: GNOME documents maintainer(s)
GNOME documents maintainer(s)
Depends on:
Blocks:
 
 
Reported: 2017-04-07 12:23 UTC by Debarshi Ray
Modified: 2017-04-20 16:12 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
documents: Specify uriToLoad for GoogleDocument (1.23 KB, patch)
2017-04-07 12:32 UTC, Debarshi Ray
committed Details | Review
documents: Implement downloadImpl for GoogleDocument (3.03 KB, patch)
2017-04-07 12:33 UTC, Debarshi Ray
committed Details | Review
documents, pdf-loader: Reduce the reliance on GdPdfLoader for Google (14.51 KB, patch)
2017-04-07 13:12 UTC, Debarshi Ray
committed Details | Review
documents: Use a global named constant for the ownCloud prefix (1.03 KB, patch)
2017-04-07 14:11 UTC, Debarshi Ray
committed Details | Review
documents, pdf-loader: Reduce the reliance on GdPdfLoader for ownCloud (9.86 KB, patch)
2017-04-07 15:21 UTC, Debarshi Ray
committed Details | Review
pdf-loader: Remove the unused unoconv-based PDF conversion code (17.51 KB, patch)
2017-04-07 16:13 UTC, Debarshi Ray
committed Details | Review
documents: Add a generic load implementation to DocCommon (7.20 KB, patch)
2017-04-07 16:45 UTC, Debarshi Ray
committed Details | Review
documents: Implement downloadImpl for GoogleDocument (3.02 KB, patch)
2017-04-12 12:47 UTC, Debarshi Ray
committed Details | Review
pdf-loader: Remove unused function (1.14 KB, patch)
2017-04-12 13:05 UTC, Debarshi Ray
committed Details | Review

Description Debarshi Ray 2017-04-07 12:23:13 UTC
In bug 774937, as a side-effect of fixing loading of LOKDocView-supported OneDrive documents, we moved a big chunk of the OneDrive loading code path from GdPdfLoader to DocCommon and SkydriveDocument. This was enabled by the fact that EvView is no longer the only renderer we have.

The obvious benefit is that it replaces a maze of asynchronous C code with JavaScript.

Secondly, we were needlessly hitting the network when loading a remote document even if there was a valid copy in the cache because we were creating a ZpjEntry or GDataEntry as the first step. The new JS-based code paths don't do that. They only use the network if there is a cache miss.

Thirdly, ODFs and OOXMLs from ownCloud were not being cached at all since the introduction of LOKDocView.

This also tweaks the structure of the cache a bit. The old scheme was:
  ~/.cache/gnome-documents/gnome-documents-<g_str_hash(id)>.pdf
The new one is:
  ~/.cache/gnome-documents/skydrive/<SHA1(id)>.<original-extension>

Debugging is easier if (a) the cache is namespaced by the source of the documents because one can selectively nuke a subset of the cache, and (b) uses a hash function that is easily replicated by other tools because one can "manually" match the original ID to the cache entry.
Comment 1 Debarshi Ray 2017-04-07 12:32:49 UTC
Created attachment 349467 [details] [review]
documents: Specify uriToLoad for GoogleDocument
Comment 2 Debarshi Ray 2017-04-07 12:33:04 UTC
Created attachment 349468 [details] [review]
documents: Implement downloadImpl for GoogleDocument
Comment 3 Debarshi Ray 2017-04-07 13:12:42 UTC
Created attachment 349473 [details] [review]
documents, pdf-loader: Reduce the reliance on GdPdfLoader for Google
Comment 4 Debarshi Ray 2017-04-07 14:11:48 UTC
Created attachment 349484 [details] [review]
documents: Use a global named constant for the ownCloud prefix
Comment 5 Debarshi Ray 2017-04-07 15:21:12 UTC
Created attachment 349488 [details] [review]
documents, pdf-loader: Reduce the reliance on GdPdfLoader for ownCloud
Comment 6 Debarshi Ray 2017-04-07 16:13:21 UTC
Created attachment 349493 [details] [review]
pdf-loader: Remove the unused unoconv-based PDF conversion code
Comment 7 Debarshi Ray 2017-04-07 16:17:59 UTC
Is there any logging facility other than 'log' in gjs?

I am wondering whether we can add some debug messages. In this case, it will be useful to log the different loading stages so that I can convince myself that the caching is working as expected. However, those messages are going to be noise for most users.
Comment 8 Debarshi Ray 2017-04-07 16:45:18 UTC
Created attachment 349494 [details] [review]
documents: Add a generic load implementation to DocCommon
Comment 9 Alessandro Bono 2017-04-07 17:05:58 UTC
(In reply to Debarshi Ray from comment #7)
> Is there any logging facility other than 'log' in gjs?
> 
> I am wondering whether we can add some debug messages. In this case, it will
> be useful to log the different loading stages so that I can convince myself
> that the caching is working as expected. However, those messages are going
> to be noise for most users.

Maps implements its own debug function:
https://git.gnome.org/browse/gnome-maps/tree/src/utils.js#n45
Comment 10 Cosimo Cecchi 2017-04-07 17:48:01 UTC
Review of attachment 349467 [details] [review]:

Looks good.
Comment 11 Cosimo Cecchi 2017-04-07 17:48:56 UTC
Review of attachment 349468 [details] [review]:

Feel free to push with this fixed.

::: src/documents.js
@@ +942,3 @@
+
+                try {
+                    return;

Single quotes.
Comment 12 Cosimo Cecchi 2017-04-07 17:51:12 UTC
Review of attachment 349473 [details] [review]:

Nice!
Comment 13 Cosimo Cecchi 2017-04-07 17:51:26 UTC
Review of attachment 349484 [details] [review]:

++
Comment 14 Cosimo Cecchi 2017-04-07 17:53:56 UTC
Review of attachment 349488 [details] [review]:

Nice!
Comment 15 Cosimo Cecchi 2017-04-07 17:55:16 UTC
Review of attachment 349493 [details] [review]:

Yay!
Comment 16 Cosimo Cecchi 2017-04-07 17:55:53 UTC
Review of attachment 349494 [details] [review]:

++
Comment 17 Cosimo Cecchi 2017-04-07 18:00:51 UTC
(In reply to Debarshi Ray from comment #7)
> Is there any logging facility other than 'log' in gjs?
> 
> I am wondering whether we can add some debug messages. In this case, it will
> be useful to log the different loading stages so that I can convince myself
> that the caching is working as expected. However, those messages are going
> to be noise for most users.

I don't think gjs has it natively, but gnome-documents has an Utils.debug() function that you could use for this.
Comment 18 Debarshi Ray 2017-04-09 00:47:38 UTC
(In reply to Alessandro Bono from comment #9)
> (In reply to Debarshi Ray from comment #7)
> > Is there any logging facility other than 'log' in gjs?
> > 
> > I am wondering whether we can add some debug messages. In this case, it will
> > be useful to log the different loading stages so that I can convince myself
> > that the caching is working as expected. However, those messages are going
> > to be noise for most users.
> 
> Maps implements its own debug function:
> https://git.gnome.org/browse/gnome-maps/tree/src/utils.js#n45

Nice. That's also the same thing Cosimo pointed out:

(In reply to Cosimo Cecchi from comment #17)
> I don't think gjs has it natively, but gnome-documents has an Utils.debug()
> function that you could use for this.

Thanks!
Comment 19 Debarshi Ray 2017-04-12 12:47:37 UTC
Created attachment 349726 [details] [review]
documents: Implement downloadImpl for GoogleDocument

Replaced double-quotes around "pdf" with single quotes and pushed.
Comment 20 Debarshi Ray 2017-04-12 13:05:46 UTC
Created attachment 349727 [details] [review]
pdf-loader: Remove unused function

This should have been a part of attachment 349473 [details] [review]. I had it in my local version of the patch but forgot to update the one that was attached to this bug.
Comment 21 Cosimo Cecchi 2017-04-12 17:41:48 UTC
Review of attachment 349727 [details] [review]:

Even better!
Comment 22 Debarshi Ray 2017-04-20 16:12:33 UTC
(In reply to Debarshi Ray from comment #0)
> The obvious benefit is that it replaces a maze of asynchronous C code with
> JavaScript.
> 
> Secondly, we were needlessly hitting the network when loading a remote
> document even if there was a valid copy in the cache because we were
> creating a ZpjEntry or GDataEntry as the first step. The new JS-based code
> paths don't do that. They only use the network if there is a cache miss.
> 
> Thirdly, ODFs and OOXMLs from ownCloud were not being cached at all since
> the introduction of LOKDocView.
> 
> This also tweaks the structure of the cache a bit. The old scheme was:
>   ~/.cache/gnome-documents/gnome-documents-<g_str_hash(id)>.pdf
> The new one is:
>   ~/.cache/gnome-documents/skydrive/<SHA1(id)>.<original-extension>
> 
> Debugging is easier if (a) the cache is namespaced by the source of the
> documents because one can selectively nuke a subset of the cache, and (b)
> uses a hash function that is easily replicated by other tools because one
> can "manually" match the original ID to the cache entry.

Another positive side-effect is that we can now load encrypted PDFs from Google. Earlier we'd delete the cached copy when we got the first EV_DOCUMENT_ERROR_ENCRYPTED, and we never specify the password (even if the user entered one) until we got the first EV_DOCUMENT_ERROR_ENCRYPTED. This meant that we used to keep asking the user for the password indefinitely.