From d2cae697b83988da8d496c693b821c8af51c8ac3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?R=C3=A9mi=20Marseault?=
<22910497+Larsluph@users.noreply.github.com>
Date: Mon, 3 Jul 2023 07:12:05 +0200
Subject: [PATCH] perf: Add qbit refresh interval setting (#923)
---
.../Settings/Tabs/VueTorrent/VGeneral.vue | 14 ++++++++++++-
src/helpers.js | 3 +--
src/lang/en.json | 2 ++
src/schemas/StoreState.ts | 2 ++
src/store/actions.ts | 2 +-
src/store/index.ts | 3 ++-
src/types/vuetorrent/WebUISettings.ts | 1 +
src/utils/faker.ts | 20 +++++++++----------
src/views/Dashboard.vue | 10 +++++-----
tests/unit/General.spec.ts | 1 +
tests/unit/__snapshots__/General.spec.ts.snap | 5 ++++-
11 files changed, 42 insertions(+), 21 deletions(-)
diff --git a/src/components/Settings/Tabs/VueTorrent/VGeneral.vue b/src/components/Settings/Tabs/VueTorrent/VGeneral.vue
index 1d4a4a48..43931b91 100644
--- a/src/components/Settings/Tabs/VueTorrent/VGeneral.vue
+++ b/src/components/Settings/Tabs/VueTorrent/VGeneral.vue
@@ -44,6 +44,16 @@
+
+
+
+
@@ -86,7 +96,9 @@
diff --git a/src/helpers.js b/src/helpers.js
index 26c5e45c..73f12ec5 100644
--- a/src/helpers.js
+++ b/src/helpers.js
@@ -161,8 +161,7 @@ export function getVersion() {
return 'import.meta.env.VITE_PACKAGE_VERSION'
}
- // return import.meta.env['VITE_PACKAGE_VERSION']
- return 'undefined'
+ return `${import.meta.env['VITE_PACKAGE_VERSION']}-dev`
}
export function getBaseURL() {
diff --git a/src/lang/en.json b/src/lang/en.json
index bad8114d..f30f606c 100644
--- a/src/lang/en.json
+++ b/src/lang/en.json
@@ -269,6 +269,8 @@
"dateFormat": "Date Format",
"openSideBarOnStart": "Open Side Bar on launch",
"showShutdownButton": "Show shutdown button",
+ "refreshInterval": "qBittorrent API refresh interval",
+ "refreshIntervalHint": "In milliseconds",
"currentVersion": "Current Version",
"qbittorrentVersion": "QBittorrent Version",
"registerMagnet": "Register magnet links",
diff --git a/src/schemas/StoreState.ts b/src/schemas/StoreState.ts
index daf16102..c54196c5 100644
--- a/src/schemas/StoreState.ts
+++ b/src/schemas/StoreState.ts
@@ -42,6 +42,7 @@ export const StoreStateSchema: JSONSchemaType = {
dateFormat: { type: 'string' },
openSideBarOnStart: { type: 'boolean' },
showShutdownButton: { type: 'boolean' },
+ refreshInterval: { type: 'number' },
busyDesktopTorrentProperties: { $ref: '/schemas/desktopDashboardProperties' },
doneDesktopTorrentProperties: { $ref: '/schemas/desktopDashboardProperties' },
busyMobileCardProperties: { $ref: '/schemas/mobileDashboardProperties' },
@@ -65,6 +66,7 @@ export const StoreStateSchema: JSONSchemaType = {
'dateFormat',
'openSideBarOnStart',
'showShutdownButton',
+ 'refreshInterval',
'busyDesktopTorrentProperties',
'doneDesktopTorrentProperties',
'busyMobileCardProperties',
diff --git a/src/store/actions.ts b/src/store/actions.ts
index f7811409..2a7acbe9 100644
--- a/src/store/actions.ts
+++ b/src/store/actions.ts
@@ -9,7 +9,7 @@ export default {
INIT_INTERVALS: async (store: Store) => {
store.state.intervals[0] = setInterval(() => {
store.commit('updateMainData')
- }, 2000)
+ }, store.state.webuiSettings.refreshInterval)
},
LOGIN: async (store: Store, payload: LoginPayload) => {
const res = await qbit.login(payload)
diff --git a/src/store/index.ts b/src/store/index.ts
index b10d1085..3c779a34 100644
--- a/src/store/index.ts
+++ b/src/store/index.ts
@@ -81,7 +81,6 @@ export default new Vuex.Store({
plugins: [vuexPersist.plugin],
state: {
authenticated: false,
- oldSettingsDetected: false,
categories: [],
dashboard: {
currentPage: 1,
@@ -93,6 +92,7 @@ export default new Vuex.Store({
isUpdatingMainData: false,
latestSelectedTorrent: -1,
modals: [],
+ oldSettingsDetected: false,
rid: 0,
rss: {
feeds: [],
@@ -135,6 +135,7 @@ export default new Vuex.Store({
dateFormat: 'DD/MM/YYYY, HH:mm:ss',
openSideBarOnStart: true,
showShutdownButton: true,
+ refreshInterval: 2000,
busyDesktopTorrentProperties: JSON.parse(JSON.stringify(desktopPropertiesTemplate)),
doneDesktopTorrentProperties: JSON.parse(JSON.stringify(desktopPropertiesTemplate)),
busyMobileCardProperties: JSON.parse(JSON.stringify(mobilePropertiesTemplate)),
diff --git a/src/types/vuetorrent/WebUISettings.ts b/src/types/vuetorrent/WebUISettings.ts
index e833947b..d1367343 100644
--- a/src/types/vuetorrent/WebUISettings.ts
+++ b/src/types/vuetorrent/WebUISettings.ts
@@ -28,6 +28,7 @@ export default interface WebUISettings {
dateFormat: string
openSideBarOnStart: boolean
showShutdownButton: boolean
+ refreshInterval: number
busyDesktopTorrentProperties: TorrentProperty[]
doneDesktopTorrentProperties: TorrentProperty[]
busyMobileCardProperties: TorrentProperty[]
diff --git a/src/utils/faker.ts b/src/utils/faker.ts
index 45b088e0..b95c88cc 100644
--- a/src/utils/faker.ts
+++ b/src/utils/faker.ts
@@ -16,19 +16,19 @@ export function generateMultiple(count: number = 1): Torrent[] {
export function generateTorrent(data: any): Torrent {
return new Torrent({
name: data.name,
- hash: faker.datatype.uuid(),
- size: faker.datatype.number({ min: 1000000, max: 50000000000 }),
+ hash: faker.string.uuid(),
+ size: faker.number.int({ min: 1000000, max: 50000000000 }),
tags: [],
- progress: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
+ progress: faker.number.int({ min: 0, max: 1, precision: 0.01 }),
state: faker.helpers.arrayElement(['done', 'downloading', 'fail', 'paused', 'queued', 'seeding', 'checking', 'stalled', 'metadata', 'moving']),
- eta: faker.datatype.number({ min: 1000, max: 900000 }),
- availability: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
+ eta: faker.number.int({ min: 1000, max: 900000 }),
+ availability: faker.number.int({ min: 0, max: 1, precision: 0.01 }),
added_on: faker.date.recent(),
- ratio: faker.datatype.number({ min: 0, max: 1, precision: 0.01 }),
- num_leechs: faker.datatype.number({ min: 1, max: 20 }),
- num_complete: faker.datatype.number({ min: 1, max: 500 }),
- num_seeds: faker.datatype.number({ min: 1, max: 25 }),
- num_incomplete: faker.datatype.number({ min: 1, max: 500 }),
+ ratio: faker.number.int({ min: 0, max: 1, precision: 0.01 }),
+ num_leechs: faker.number.int({ min: 1, max: 20 }),
+ num_complete: faker.number.int({ min: 1, max: 500 }),
+ num_seeds: faker.number.int({ min: 1, max: 25 }),
+ num_incomplete: faker.number.int({ min: 1, max: 500 }),
save_path: faker.system.filePath(),
category: faker.helpers.arrayElement(['ISO', 'Other', 'Movie', 'Music', 'TV'])
})
diff --git a/src/views/Dashboard.vue b/src/views/Dashboard.vue
index 61c21e96..facca025 100644
--- a/src/views/Dashboard.vue
+++ b/src/views/Dashboard.vue
@@ -330,6 +330,11 @@ export default {
}
}
},
+ created() {
+ this.$store.commit('FETCH_CATEGORIES')
+ this.$store.commit('FETCH_TAGS')
+ if (this.input) this.searchFilterEnabled = true
+ },
mounted() {
this.$store.dispatch('INIT_INTERVALS')
document.addEventListener('keydown', this.handleKeyboardShortcut)
@@ -342,11 +347,6 @@ export default {
this.$store.dispatch('ALERT_OLD_SETTINGS')
}
},
- created() {
- this.$store.commit('FETCH_CATEGORIES')
- this.$store.commit('FETCH_TAGS')
- if (this.input) this.searchFilterEnabled = true
- },
beforeDestroy() {
this.$store.commit('REMOVE_INTERVALS')
document.removeEventListener('keydown', this.handleKeyboardShortcut)
diff --git a/tests/unit/General.spec.ts b/tests/unit/General.spec.ts
index aff40be4..7308048a 100644
--- a/tests/unit/General.spec.ts
+++ b/tests/unit/General.spec.ts
@@ -20,6 +20,7 @@ describe('General', () => {
$store: {
getters: { getAppVersion: vi.fn() },
state: {
+ version: 'test',
webuiSettings: {
showCurrentSpeed: 100,
showSpeedGraph: true,
diff --git a/tests/unit/__snapshots__/General.spec.ts.snap b/tests/unit/__snapshots__/General.spec.ts.snap
index 7937007d..2ac68eef 100644
--- a/tests/unit/__snapshots__/General.spec.ts.snap
+++ b/tests/unit/__snapshots__/General.spec.ts.snap
@@ -33,6 +33,9 @@ exports[`General > render correctly 1`] = `
+
+
+
@@ -55,7 +58,7 @@ exports[`General > render correctly 1`] = `
-
+ undefined