mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06: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:
@@ -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();
|
||||
})();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user