Skip to content

Commit

Permalink
Reduce bandwith usage
Browse files Browse the repository at this point in the history
  • Loading branch information
6c65726f79 committed Dec 1, 2021
1 parent 72d62f3 commit bdc36fe
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 8 deletions.
7 changes: 5 additions & 2 deletions src/services/TransmissionRPC.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,10 +213,10 @@ class TRPC {
return token;
}

async getTorrents() {
async getTorrents(refresh=false) {
let result: Array<any>=[];
let loadPersistent=false;
const args = {
const args: Record<string,any> = {
fields: [
'id',
'name',
Expand All @@ -237,6 +237,9 @@ class TRPC {
'queuePosition'
]
}
if(refresh) {
args.ids = "recently-active";
}

if(!this.persistentDataValid){
loadPersistent=true;
Expand Down
33 changes: 27 additions & 6 deletions src/views/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ import { LocaleController } from "../services/LocaleController";
import { Utils } from "../services/Utils";
import { Emitter } from "../services/Emitter";
import { SplashScreen } from '@capacitor/splash-screen';
import * as _ from 'lodash';
export default defineComponent({
name: 'App',
Expand Down Expand Up @@ -313,7 +314,6 @@ export default defineComponent({
language() {
LocaleController.setLanguage(UserSettings.getLanguage());
},
"privateState.torrentList": function() { this.getTorrentFilters() },
"privateState.serverList.length": async function() {
if(this.privateState.selectedServer>=this.privateState.serverList.length){
this.privateState.selectedServer=this.privateState.serverList.length-1;
Expand Down Expand Up @@ -386,14 +386,14 @@ export default defineComponent({
clearInterval(this.privateState.refresh);
this.privateState.refresh = setInterval(() => {
if(!this.privateState.connectionStatus.loading && this.privateState.connectionStatus.error=="") {
this.getTorrents()
this.getTorrents(false, true)
}
},this.sharedState.refreshInterval*1000);
},
refresh(clean=false) {
this.setRefreshInterval();
this.getTorrents(clean);
this.getTorrents(clean, false);
},
openTrackerList(e: Event) {
Expand Down Expand Up @@ -456,6 +456,10 @@ export default defineComponent({
component: Settings,
cssClass: 'settings'
})
modal.onDidDismiss()
.then(() => {
this.refresh(false)
})
return modal.present();
},
Expand All @@ -464,6 +468,10 @@ export default defineComponent({
.create({
component: About
})
modal.onDidDismiss()
.then(() => {
this.refresh(false)
})
return modal.present();
},
Expand All @@ -481,6 +489,10 @@ export default defineComponent({
add:add
}
})
modal.onDidDismiss()
.then(() => {
this.refresh(false)
})
return modal.present();
},
Expand Down Expand Up @@ -509,7 +521,7 @@ export default defineComponent({
})
},
async getTorrents(clean=false) {
async getTorrents(clean=false, refresh=false) {
const isModalOpened = await modalController.getTop();
if(!isModalOpened || clean){
this.privateState.connectionStatus.loading=true;
Expand All @@ -518,11 +530,20 @@ export default defineComponent({
this.privateState.connectionStatus.error="";
this.privateState.torrentList=[];
}
TransmissionRPC.getTorrents()
TransmissionRPC.getTorrents((refresh && !clean))
.then((response) => {
this.privateState.connectionStatus.error="";
this.privateState.connectionStatus.connected=true;
this.privateState.torrentList=response;
if(refresh){
this.privateState.torrentList = _.unionBy(response, this.privateState.torrentList, 'id');
if(response.length>0){
this.getTorrentFilters();
}
}
else {
this.privateState.torrentList = response;
this.getTorrentFilters();
}
})
.catch((error) => {
if(error.message){
Expand Down

0 comments on commit bdc36fe

Please sign in to comment.