ソースを参照

Avoids thrashing on checkin calls

main
Eric Amodio 2年前
コミット
64750314ef
3個のファイルの変更24行の追加3行の削除
  1. +1
    -0
      src/plus/subscription/subscriptionService.ts
  2. +21
    -3
      src/webviews/home/homeWebviewView.ts
  3. +2
    -0
      src/webviews/webviewViewBase.ts

+ 1
- 0
src/plus/subscription/subscriptionService.ts ファイルの表示

@ -522,6 +522,7 @@ export class SubscriptionService implements Disposable {
} }
private _lastCheckInDate: Date | undefined; private _lastCheckInDate: Date | undefined;
@gate<SubscriptionService['checkInAndValidate']>(s => s.account.id)
private async checkInAndValidate(session: AuthenticationSession, showSlowProgress: boolean = false): Promise<void> { private async checkInAndValidate(session: AuthenticationSession, showSlowProgress: boolean = false): Promise<void> {
if (!showSlowProgress) return this.checkInAndValidateCore(session); if (!showSlowProgress) return this.checkInAndValidateCore(session);

+ 21
- 3
src/webviews/home/homeWebviewView.ts ファイルの表示

@ -10,6 +10,8 @@ import type { SubscriptionChangeEvent } from '../../plus/subscription/subscripti
import { ensurePlusFeaturesEnabled } from '../../plus/subscription/utils'; import { ensurePlusFeaturesEnabled } from '../../plus/subscription/utils';
import type { Subscription } from '../../subscription'; import type { Subscription } from '../../subscription';
import { executeCoreCommand, registerCommand } from '../../system/command'; import { executeCoreCommand, registerCommand } from '../../system/command';
import type { Deferrable } from '../../system/function';
import { debounce } from '../../system/function';
import type { IpcMessage } from '../protocol'; import type { IpcMessage } from '../protocol';
import { onIpc } from '../protocol'; import { onIpc } from '../protocol';
import { WebviewViewBase } from '../webviewViewBase'; import { WebviewViewBase } from '../webviewViewBase';
@ -45,13 +47,19 @@ export class HomeWebviewView extends WebviewViewBase {
} }
protected override onVisibilityChanged(visible: boolean): void { protected override onVisibilityChanged(visible: boolean): void {
if (!visible) return;
if (!visible) {
this._validateSubscriptionDebounced?.cancel();
return;
}
queueMicrotask(() => void this.validateSubscription()); queueMicrotask(() => void this.validateSubscription());
} }
protected override onWindowFocusChanged(focused: boolean): void { protected override onWindowFocusChanged(focused: boolean): void {
if (!focused) return;
if (!focused || !this.visible) {
this._validateSubscriptionDebounced?.cancel();
return;
}
queueMicrotask(() => void this.validateSubscription()); queueMicrotask(() => void this.validateSubscription());
} }
@ -198,8 +206,18 @@ export class HomeWebviewView extends WebviewViewBase {
}); });
} }
private _validating: Promise<void> | undefined;
private _validateSubscriptionDebounced: Deferrable<HomeWebviewView['validateSubscription']> | undefined = undefined;
private async validateSubscription(): Promise<void> { private async validateSubscription(): Promise<void> {
if (this._validateSubscriptionDebounced == null) {
this._validateSubscriptionDebounced = debounce(this.validateSubscriptionCore, 1000);
}
await this._validateSubscriptionDebounced();
}
private _validating: Promise<void> | undefined;
private async validateSubscriptionCore() {
if (this._validating == null) { if (this._validating == null) {
this._validating = this.container.subscription.validate(); this._validating = this.container.subscription.validate();
try { try {

+ 2
- 0
src/webviews/webviewViewBase.ts ファイルの表示

@ -155,6 +155,8 @@ export abstract class WebviewViewBase implements
} }
private onWindowStateChanged(e: WindowState) { private onWindowStateChanged(e: WindowState) {
if (!this.visible) return;
this.onWindowFocusChanged?.(e.focused); this.onWindowFocusChanged?.(e.focused);
} }

読み込み中…
キャンセル
保存