Skip to content

Commit

Permalink
reduce multiple xhr reloads when study gets many new chapters
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed Dec 29, 2024
1 parent 9e1fa11 commit b4acc15
Showing 1 changed file with 15 additions and 12 deletions.
27 changes: 15 additions & 12 deletions ui/analyse/src/study/studyCtrl.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { DrawShape } from 'chessground/draw';
import { prop, defined } from 'common';
import { debounce, throttle, throttlePromise } from 'common/timing';
import { debounce, throttle, throttlePromiseDelay } from 'common/timing';
import type AnalyseCtrl from '../ctrl';
import { StudyMemberCtrl } from './studyMembers';
import StudyPracticeCtrl from './practice/studyPracticeCtrl';
Expand Down Expand Up @@ -377,17 +377,20 @@ export default class StudyCtrl {
this.updateAddressBar();
};

xhrReload = throttlePromise((withChapters: boolean = false) => {
this.vm.loading = true;
return xhr
.reload(
this.practice ? 'practice/load' : 'study',
this.data.id,
this.vm.mode.sticky ? undefined : this.vm.chapterId,
(withChapters = withChapters),
)
.then(this.onReload, site.reload);
});
xhrReload = throttlePromiseDelay(
() => 500,
(withChapters: boolean = false) => {
this.vm.loading = true;
return xhr
.reload(
this.practice ? 'practice/load' : 'study',
this.data.id,
this.vm.mode.sticky ? undefined : this.vm.chapterId,
(withChapters = withChapters),
)
.then(this.onReload, site.reload);
},
);

onSetPath = throttle(300, (path: Tree.Path) => {
if (this.vm.mode.sticky && path !== this.data.position.path)
Expand Down

0 comments on commit b4acc15

Please sign in to comment.