Skip to content

Commit

Permalink
reload tournament data less often, unless you're joining
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 5, 2018
1 parent 39b27cb commit a27bac3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 6 deletions.
5 changes: 5 additions & 0 deletions ui/tournament/src/ctrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ export default class TournamentController {
if (this.data.featured) this.startWatching(this.data.featured.id);
}

askReload = (): void => {
if (this.joinSpinner) xhr.reloadNow(this);
else xhr.reloadSoon(this);
};

reload = (data: TournamentData): void => {
this.data = data;
if (data.playerInfo && data.playerInfo.player.id === this.playerInfo.id)
Expand Down
5 changes: 1 addition & 4 deletions ui/tournament/src/socket.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import xhr from './xhr';
import TournamentController from './ctrl';

export interface TournamentSocket {
Expand All @@ -9,9 +8,7 @@ export interface TournamentSocket {
export default function(send: SocketSend, ctrl: TournamentController) {

const handlers = {
reload() {
xhr.reloadTournament(ctrl);
},
reload: ctrl.askReload,
redirect(fullId) {
ctrl.redirectFirst(fullId.slice(0, 8), true);
return true;
Expand Down
5 changes: 3 additions & 2 deletions ui/tournament/src/xhr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function loadPageOf(ctrl: TournamentController, userId: string): JQueryXHR {
});
}

function reloadTournament(ctrl: TournamentController) {
function reload(ctrl: TournamentController) {
return $.ajax({
url: '/tournament/' + ctrl.data.id,
data: {
Expand Down Expand Up @@ -75,6 +75,7 @@ export default {
withdraw: throttle(1000, withdraw),
loadPage: throttle(1000, loadPage),
loadPageOf,
reloadTournament: throttle(2000, reloadTournament),
reloadSoon: throttle(3000, reload),
reloadNow: reload,
playerInfo
};

0 comments on commit a27bac3

Please sign in to comment.