E-book viewer: Fix a regression that caused an increase in load times when loading the individual HTML files inside an EPUB book. Fixes #1658578 [loading flow delay for every page](https://bugs.launchpad.net/calibre/+bug/1658578)

This commit is contained in:
Kovid Goyal 2017-01-23 12:41:08 +05:30
parent 5fde1b3ffb
commit 1027a80786
2 changed files with 6 additions and 1 deletions

View File

@ -6,7 +6,7 @@ from __future__ import (unicode_literals, division, absolute_import,
print_function) print_function)
import os import os
from PyQt5.Qt import QNetworkReply, QNetworkAccessManager, QUrl, QNetworkRequest, QTimer, pyqtSignal from PyQt5.Qt import QNetworkReply, QNetworkAccessManager, QUrl, QNetworkRequest, QTimer, pyqtSignal, QByteArray
from calibre import guess_type as _guess_type, prints from calibre import guess_type as _guess_type, prints
from calibre.constants import FAKE_HOST, FAKE_PROTOCOL, DEBUG from calibre.constants import FAKE_HOST, FAKE_PROTOCOL, DEBUG
@ -19,6 +19,9 @@ def guess_type(x):
return _guess_type(x)[0] or 'application/octet-stream' return _guess_type(x)[0] or 'application/octet-stream'
cc_header = QByteArray(b'Cache-Control'), QByteArray(b'max-age=864001')
class NetworkReply(QNetworkReply): class NetworkReply(QNetworkReply):
def __init__(self, parent, request, mime_type, data): def __init__(self, parent, request, mime_type, data):
@ -30,6 +33,7 @@ class NetworkReply(QNetworkReply):
self.__data = data self.__data = data
self.setHeader(QNetworkRequest.ContentTypeHeader, mime_type) self.setHeader(QNetworkRequest.ContentTypeHeader, mime_type)
self.setHeader(QNetworkRequest.ContentLengthHeader, len(self.__data)) self.setHeader(QNetworkRequest.ContentLengthHeader, len(self.__data))
self.setRawHeader(*cc_header)
QTimer.singleShot(0, self.finalize_reply) QTimer.singleShot(0, self.finalize_reply)
def bytesAvailable(self): def bytesAvailable(self):

View File

@ -954,6 +954,7 @@ class EbookViewer(MainWindow):
while worker.isAlive(): while worker.isAlive():
worker.join(0.1) worker.join(0.1)
QApplication.processEvents() QApplication.processEvents()
self.view.settings().clearMemoryCaches()
if worker.exception is not None: if worker.exception is not None:
tb = worker.traceback.strip() tb = worker.traceback.strip()
if tb and tb.splitlines()[-1].startswith('DRMError:'): if tb and tb.splitlines()[-1].startswith('DRMError:'):