mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-10-22 02:36:15 +03:00
Migrate to Cache for commonly used data
Previously it was abusing the `localStorage` and now it is storing data in memory (per session).
This commit is contained in:
parent
d06d5b923a
commit
963a7faab8
4 changed files with 73 additions and 54 deletions
|
@ -34,10 +34,33 @@ if (window.qBittorrent === undefined)
|
|||
window.qBittorrent.Cache = (() => {
|
||||
const exports = () => {
|
||||
return {
|
||||
preferences: new PreferencesCache()
|
||||
buildInfo: new BuildInfoCache(),
|
||||
preferences: new PreferencesCache(),
|
||||
qbtVersion: new QbtVersionCache()
|
||||
};
|
||||
};
|
||||
|
||||
class BuildInfoCache {
|
||||
#m_store = {};
|
||||
|
||||
init() {
|
||||
new Request.JSON({
|
||||
url: 'api/v2/app/buildInfo',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: (responseJSON) => {
|
||||
if (!responseJSON)
|
||||
return;
|
||||
this.#m_store = responseJSON;
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
get() {
|
||||
return structuredClone(this.#m_store);
|
||||
}
|
||||
}
|
||||
|
||||
class PreferencesCache {
|
||||
#m_store = {};
|
||||
|
||||
|
@ -106,6 +129,27 @@ window.qBittorrent.Cache = (() => {
|
|||
}
|
||||
}
|
||||
|
||||
class QbtVersionCache {
|
||||
#m_store = '';
|
||||
|
||||
init() {
|
||||
new Request({
|
||||
url: 'api/v2/app/version',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: (responseText) => {
|
||||
if (!responseText)
|
||||
return;
|
||||
this.#m_store = responseText;
|
||||
}
|
||||
}).send();
|
||||
}
|
||||
|
||||
get() {
|
||||
return this.#m_store;
|
||||
}
|
||||
}
|
||||
|
||||
return exports();
|
||||
})();
|
||||
|
||||
|
|
|
@ -34,8 +34,7 @@ window.qBittorrent.Client = (() => {
|
|||
return {
|
||||
closeWindows: closeWindows,
|
||||
genHash: genHash,
|
||||
getSyncMainDataInterval: getSyncMainDataInterval,
|
||||
qbtVersion: qbtVersion
|
||||
getSyncMainDataInterval: getSyncMainDataInterval
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -57,10 +56,6 @@ window.qBittorrent.Client = (() => {
|
|||
return customSyncMainDataInterval ? customSyncMainDataInterval : serverSyncMainDataInterval;
|
||||
};
|
||||
|
||||
const qbtVersion = function() {
|
||||
return LocalPreferences.get('qbtVersion', '');
|
||||
};
|
||||
|
||||
return exports();
|
||||
})();
|
||||
Object.freeze(window.qBittorrent.Client);
|
||||
|
@ -110,7 +105,7 @@ let selected_filter = LocalPreferences.get('selected_filter', 'all');
|
|||
let setFilter = function() {};
|
||||
let toggleFilterDisplay = function() {};
|
||||
|
||||
window.addEvent('load', function() {
|
||||
window.addEventListener("DOMContentLoaded", function() {
|
||||
const saveColumnSizes = function() {
|
||||
const filters_width = $('Filters').getSize().x;
|
||||
const properties_height_rel = $('propertiesPanel').getSize().y / Window.getSize().y;
|
||||
|
@ -869,12 +864,15 @@ window.addEvent('load', function() {
|
|||
transfer_info += " [" + window.qBittorrent.Misc.friendlyUnit(serverState.up_rate_limit, true) + "]";
|
||||
transfer_info += " (" + window.qBittorrent.Misc.friendlyUnit(serverState.up_info_data, false) + ")";
|
||||
$("UpInfos").set('html', transfer_info);
|
||||
|
||||
const qbtVersion = window.qBittorrent.Cache.qbtVersion.get();
|
||||
|
||||
if (speedInTitle) {
|
||||
document.title = "QBT_TR([D: %1, U: %2] qBittorrent %3)QBT_TR[CONTEXT=MainWindow]".replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true)).replace("%2", window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true)).replace("%3", window.qBittorrent.Client.qbtVersion());
|
||||
document.title = "QBT_TR([D: %1, U: %2] qBittorrent %3)QBT_TR[CONTEXT=MainWindow]".replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.dl_info_speed, true)).replace("%2", window.qBittorrent.Misc.friendlyUnit(serverState.up_info_speed, true)).replace("%3", qbtVersion);
|
||||
document.title += " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]";
|
||||
}
|
||||
else
|
||||
document.title = ("qBittorrent " + window.qBittorrent.Client.qbtVersion() + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
|
||||
document.title = ("qBittorrent " + qbtVersion + " QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]");
|
||||
$('freeSpaceOnDisk').set('html', 'QBT_TR(Free space: %1)QBT_TR[CONTEXT=HttpServer]'.replace("%1", window.qBittorrent.Misc.friendlyUnit(serverState.free_space_on_disk)));
|
||||
$('DHTNodes').set('html', 'QBT_TR(DHT: %1 nodes)QBT_TR[CONTEXT=StatusBar]'.replace("%1", serverState.dht_nodes));
|
||||
|
||||
|
@ -1575,38 +1573,11 @@ window.addEvent('load', function() {
|
|||
}
|
||||
}
|
||||
}).activate();
|
||||
|
||||
window.parent.qBittorrent.Cache.preferences.init();
|
||||
|
||||
// fetch qbt version and store it locally
|
||||
new Request({
|
||||
url: 'api/v2/app/version',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: (info) => {
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
LocalPreferences.set('qbtVersion', info);
|
||||
}
|
||||
}).send();
|
||||
|
||||
// fetch build info and store it locally
|
||||
new Request.JSON({
|
||||
url: 'api/v2/app/buildInfo',
|
||||
method: 'get',
|
||||
noCache: true,
|
||||
onSuccess: (info) => {
|
||||
if (!info)
|
||||
return;
|
||||
|
||||
LocalPreferences.set('buildInfo.qtVersion', info.qt);
|
||||
LocalPreferences.set('buildInfo.libtorrentVersion', info.libtorrent);
|
||||
LocalPreferences.set('buildInfo.boostVersion', info.boost);
|
||||
LocalPreferences.set('buildInfo.opensslVersion', info.openssl);
|
||||
LocalPreferences.set('buildInfo.zlibVersion', info.zlib);
|
||||
LocalPreferences.set('buildInfo.bitness', info.bitness);
|
||||
LocalPreferences.set('buildInfo.platform', info.platform);
|
||||
}
|
||||
}).send();
|
||||
});
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
// fetch various data and store it in memory
|
||||
window.qBittorrent.Cache.buildInfo.init();
|
||||
window.qBittorrent.Cache.preferences.init();
|
||||
window.qBittorrent.Cache.qbtVersion.init();
|
||||
});
|
||||
|
|
|
@ -843,11 +843,14 @@
|
|||
<script>
|
||||
'use strict';
|
||||
|
||||
$('qbittorrentVersion').innerText = `qBittorrent ${window.qBittorrent.Client.qbtVersion()} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]`;
|
||||
$('qtVersion').textContent = LocalPreferences.get('buildInfo.qtVersion');
|
||||
$('libtorrentVersion').textContent = LocalPreferences.get('buildInfo.libtorrentVersion');
|
||||
$('boostVersion').textContent = LocalPreferences.get('buildInfo.boostVersion');
|
||||
$('opensslVersion').textContent = LocalPreferences.get('buildInfo.opensslVersion');
|
||||
$('zlibVersion').textContent = LocalPreferences.get('buildInfo.zlibVersion');
|
||||
$('qbittorrentVersion').textContent += ` (${LocalPreferences.get('buildInfo.bitness')}-bit)`;
|
||||
const qbtVersion = window.parent.qBittorrent.Cache.qbtVersion.get();
|
||||
const buildInfo = window.parent.qBittorrent.Cache.buildInfo.get();
|
||||
|
||||
$('qbittorrentVersion').innerText = `qBittorrent ${qbtVersion} QBT_TR(Web UI)QBT_TR[CONTEXT=OptionsDialog]`;
|
||||
$('qtVersion').textContent = buildInfo.qt;
|
||||
$('libtorrentVersion').textContent = buildInfo.libtorrent;
|
||||
$('boostVersion').textContent = buildInfo.boost;
|
||||
$('opensslVersion').textContent = buildInfo.openssl;
|
||||
$('zlibVersion').textContent = buildInfo.zlib;
|
||||
$('qbittorrentVersion').textContent += ` (${buildInfo.bitness}-bit)`;
|
||||
</script>
|
||||
|
|
|
@ -1575,7 +1575,9 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
|||
};
|
||||
|
||||
// hide entries
|
||||
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(LocalPreferences.get('buildInfo.libtorrentVersion', ''));
|
||||
const buildInfo = window.qBittorrent.Cache.buildInfo.get();
|
||||
|
||||
const libtorrentVersion = window.qBittorrent.Misc.parseVersion(buildInfo.libtorrent);
|
||||
if (libtorrentVersion.valid) {
|
||||
if (libtorrentVersion.major >= 2) {
|
||||
$('rowDiskCache').style.display = 'none';
|
||||
|
@ -1597,8 +1599,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
|
|||
$('diskIOWriteModeWriteThrough').style.display = 'none';
|
||||
}
|
||||
|
||||
const serverPlatform = LocalPreferences.get('buildInfo.platform', '');
|
||||
if ((serverPlatform !== 'macos') && (serverPlatform !== 'windows'))
|
||||
if ((buildInfo.platform !== 'macos') && (buildInfo.platform !== 'windows'))
|
||||
$('rowMarkOfTheWeb').style.display = 'none';
|
||||
|
||||
// Behavior tab
|
||||
|
|
Loading…
Reference in a new issue