Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: only update changed data + code cleanup
- Loading branch information
Showing
15 changed files
with
183 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import * as _ from 'lodash' | ||
|
||
export class ArrayHelper { | ||
static remove(array, item) { | ||
const toRemove = Array.isArray(item) ? item : [item] | ||
_.remove(array, item => toRemove.indexOf(item) > -1) | ||
|
||
return array | ||
} | ||
|
||
static concat(a, b) { | ||
return _.concat(a, b) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export class Hostname { | ||
static get(url) { | ||
const match = url.match(/:\/\/(www[0-9]?\.)?(.[^/:]+)/i) | ||
if (match != null && | ||
match.length > 2 && | ||
typeof match[2] === 'string' && | ||
match[2].length > 0) { | ||
return match[2] | ||
} else { | ||
return '' | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { ArrayHelper } from './ArrayHelper' | ||
import { Hostname } from './Hostname' | ||
|
||
export { | ||
ArrayHelper, Hostname | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import store from '../store' | ||
|
||
export class Graph { | ||
static update() { | ||
const state = store.state | ||
state.download_data.shift() | ||
state.download_data.push(state.status.dlspeedRaw || 0) | ||
state.upload_data.shift() | ||
state.upload_data.push(state.status.upspeedRaw || 0) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import store from '../store' | ||
import Status from '@/models/Status' | ||
|
||
export class ServerStatus { | ||
static update(response) { | ||
if (response.server_state) { | ||
store.state.status = new Status(response.server_state) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import store from '../store' | ||
import { ArrayHelper } from '@/Helpers' | ||
|
||
export class Tags { | ||
static update(response) { | ||
if (response?.full_update === true) { | ||
store.state.tags = response.tags | ||
|
||
return | ||
} | ||
|
||
if (response.tags_removed) { | ||
store.state.tags = ArrayHelper.remove(store.state.tags, response.tags_removed) | ||
|
||
return | ||
} | ||
|
||
if (response.tags) { | ||
store.state.tags = ArrayHelper.concat(store.state.tags, response.tags) | ||
|
||
|
||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import store from '../store' | ||
import { Hostname } from '@/Helpers' | ||
import Torrent from '@/models/Torrent' | ||
|
||
export class Torrents { | ||
static update(data) { | ||
if (store.state.webuiSettings.showTrackerFilter) { // dont calculate trackers when disabled | ||
|
||
if (store.state.sort_options.tracker !== null) { | ||
data = data.filter(d => Hostname.get(d.tracker) === store.state.sort_options.tracker) | ||
} | ||
} | ||
|
||
// update torrents | ||
store.state.torrents = data.map(t => new Torrent(t)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import store from '../store' | ||
import { Hostname } from '@/Helpers' | ||
|
||
export class Trackers { | ||
static update(data) { | ||
if (store.state.webuiSettings.showTrackerFilter) { | ||
store.state.trackers = data.map(t => t.tracker) | ||
.map(url => Hostname.get(url)) | ||
.filter((domain, index, self) => index === self.indexOf(domain) && domain) | ||
.sort() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,11 @@ | ||
import { DocumentTitle } from './DocumentTitle' | ||
import { Tags } from './Tags' | ||
import { Torrents } from './Torrents' | ||
import { Trackers } from './Trackers' | ||
import { Graph } from './Graph' | ||
import { ServerStatus } from './ServerStatus' | ||
|
||
export { | ||
DocumentTitle | ||
DocumentTitle, Tags, Torrents, Trackers, | ||
Graph, ServerStatus | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
664e4db
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in 'scr/models/Status.js'
It should be replaced as instructed below.
↘
Because those 4 items are delivered even if the values are the same unless they are requested faster than Qbittorrent's internal system update timer, and if the value is 0, no reply is made.