perf: enable manual sort for priority (#845)

This commit is contained in:
Rémi Marseault 2023-06-02 21:26:38 +02:00 committed by GitHub
parent 1bc4d81481
commit 3bf470b890
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 11 additions and 2 deletions

View file

@ -12,7 +12,7 @@ dayjs.extend(relativeTime)
const durationFormat = 'D[d] H[h] m[m] s[s]'
export default class Torrent {
static computedValues = ['globalSpeed', 'globalVolume']
static computedValues = ['globalSpeed', 'globalVolume', 'priority']
added_on: string
amount_left: number

View file

@ -253,7 +253,16 @@ export default {
}
if (this.sort_options.isCustomSortEnabled) {
torrents.sort((a, b) => a[this.sort_options.sort] - b[this.sort_options.sort] || a.added_on - b.added_on)
if (this.sort_options.sort === 'priority') {
torrents.sort((a, b) => {
if (a.priority > 0 && b.priority > 0) return a.priority - b.priority
else if (a.priority <= 0 && b.priority <= 0) return a.added_on - b.added_on
else if (a.priority <= 0) return 1
else return -1
})
} else {
torrents.sort((a, b) => a[this.sort_options.sort] - b[this.sort_options.sort] || a.added_on - b.added_on)
}
if (this.sort_options.reverse) torrents.reverse()
}
return torrents