|
@@ -67,8 +67,13 @@ export class CloudFunctionsService {
|
|
|
const identity = stableRequestJson(this.sessions.session());
|
|
const identity = stableRequestJson(this.sessions.session());
|
|
|
const {refresh: _refresh,...cacheParams}=params;
|
|
const {refresh: _refresh,...cacheParams}=params;
|
|
|
const key = stableRequestJson([path, identity, cacheParams]);
|
|
const key = stableRequestJson([path, identity, cacheParams]);
|
|
|
- let requestStarted=Date.now();
|
|
|
|
|
- const execute = () => {requestStarted=Date.now();return this.http.post<T>(`${CLOUD_FUNCTION_BASE_URL}/${path}`, { token, params }).pipe(
|
|
|
|
|
|
|
+ let requestStarted = Date.now();
|
|
|
|
|
+ let passwordChangeSent = false;
|
|
|
|
|
+ const execute = () => {
|
|
|
|
|
+ requestStarted = Date.now();
|
|
|
|
|
+ // This write can invalidate its own request token before its receipt arrives.
|
|
|
|
|
+ passwordChangeSent = path === 'xiaoshu/admin/gateway' && operation === 'changeOwnPassword';
|
|
|
|
|
+ return this.http.post<T>(`${CLOUD_FUNCTION_BASE_URL}/${path}`, { token, params }).pipe(
|
|
|
timeout({ first: timeoutMs, with: () => throwError(() => new CloudFunctionError(this.transportMessage(readOnly))) }),
|
|
timeout({ first: timeoutMs, with: () => throwError(() => new CloudFunctionError(this.transportMessage(readOnly))) }),
|
|
|
retry({ count: 1, delay: (error) => {
|
|
retry({ count: 1, delay: (error) => {
|
|
|
const vocabularyRead = operation === 'ops/vocabulary/tree' || operation === 'ops/vocabulary/list';
|
|
const vocabularyRead = operation === 'ops/vocabulary/tree' || operation === 'ops/vocabulary/list';
|
|
@@ -91,7 +96,7 @@ export class CloudFunctionsService {
|
|
|
}));};
|
|
}));};
|
|
|
const scheduled = this.scheduler.schedule(execute, {
|
|
const scheduled = this.scheduler.schedule(execute, {
|
|
|
read: readOnly, key, heavy: /^ops\/(?:lessons\/(?:list|detail)|payroll\/(?:overview|export))$/.test(operation),
|
|
read: readOnly, key, heavy: /^ops\/(?:lessons\/(?:list|detail)|payroll\/(?:overview|export))$/.test(operation),
|
|
|
- background: operation === 'ops/live/versions' || operation === 'ops/lessons/export/download', valid: () => stableRequestJson(this.sessions.session()) === identity,
|
|
|
|
|
|
|
+ background: operation === 'ops/live/versions' || operation === 'ops/lessons/export/download', valid: () => passwordChangeSent || stableRequestJson(this.sessions.session()) === identity,
|
|
|
cacheMs: value=>['ops/lessons/list', 'ops/vocabulary/tree', 'ops/pay-rates/list', 'ops/teaching-rules/list'].includes(operation)?Math.max(0,((value as {data?:{clientFetchedAt?:number}}).data?.clientFetchedAt??Date.now())+30000-Date.now()):0,
|
|
cacheMs: value=>['ops/lessons/list', 'ops/vocabulary/tree', 'ops/pay-rates/list', 'ops/teaching-rules/list'].includes(operation)?Math.max(0,((value as {data?:{clientFetchedAt?:number}}).data?.clientFetchedAt??Date.now())+30000-Date.now()):0,
|
|
|
refresh: params['refresh'] === true,
|
|
refresh: params['refresh'] === true,
|
|
|
cacheable: value => (value as CloudEnvelope<unknown>)?.success === true,
|
|
cacheable: value => (value as CloudEnvelope<unknown>)?.success === true,
|