- 长轮询走独立通道(requestUnlimited),不再占用 ConcurrencyLimiter 槽位 - ConcurrencyLimiter 上限 8→12,缓解 TabBar 切换请求风暴 - 新增 safeReLaunch 去重,防止并发 401 多次触发页面跳转 - maxFailures 50→10,后端不可用时快速止损而非持续 18 分钟重试 根因:咨询页长轮询每次占用槽位 25-30s,8 个槽位被占满后 所有新请求排队等待,叠加 401 场景形成死锁。
77 lines
2.1 KiB
TypeScript
77 lines
2.1 KiB
TypeScript
import { api, requestUnlimited } from './request';
|
|
|
|
export interface ConsultationSession {
|
|
id: string;
|
|
patient_id: string;
|
|
doctor_id: string | null;
|
|
patient_name?: string | null;
|
|
doctor_name?: string | null;
|
|
consultation_type: string;
|
|
status: string;
|
|
subject?: string | null;
|
|
last_message?: string | null;
|
|
last_message_at: string | null;
|
|
unread_count_patient: number;
|
|
unread_count_doctor?: number;
|
|
created_at: string;
|
|
updated_at?: string;
|
|
version?: number;
|
|
}
|
|
|
|
export interface ConsultationMessage {
|
|
id: string;
|
|
session_id: string;
|
|
sender_id: string;
|
|
sender_role: string;
|
|
content_type: string;
|
|
content: string;
|
|
is_read: boolean;
|
|
created_at: string;
|
|
}
|
|
|
|
export async function listConsultations(params?: {
|
|
page?: number;
|
|
page_size?: number;
|
|
}) {
|
|
return api.get<{ data: ConsultationSession[]; total: number }>(
|
|
'/health/consultation-sessions',
|
|
params,
|
|
);
|
|
}
|
|
|
|
export async function getSession(sessionId: string) {
|
|
return api.get<ConsultationSession>(`/health/consultation-sessions/${sessionId}`);
|
|
}
|
|
|
|
export async function listMessages(sessionId: string, params?: {
|
|
page?: number;
|
|
page_size?: number;
|
|
after_id?: string;
|
|
}) {
|
|
return api.get<{ data: ConsultationMessage[]; total: number }>(
|
|
`/health/consultation-sessions/${sessionId}/messages`,
|
|
params,
|
|
);
|
|
}
|
|
|
|
export async function sendMessage(sessionId: string, content: string, contentType = 'text') {
|
|
return api.post<ConsultationMessage>('/health/consultation-messages', {
|
|
session_id: sessionId,
|
|
content_type: contentType,
|
|
content,
|
|
});
|
|
}
|
|
|
|
export async function markSessionRead(sessionId: string) {
|
|
return api.put<void>(`/health/consultation-sessions/${sessionId}/read`);
|
|
}
|
|
|
|
export async function pollMessages(sessionId: string, afterId?: string) {
|
|
const params = new URLSearchParams();
|
|
if (afterId) params.set('after_id', afterId);
|
|
params.set('timeout', '25');
|
|
const query = params.toString();
|
|
const path = `/health/consultation-sessions/${sessionId}/messages/poll${query ? '?' + query : ''}`;
|
|
return requestUnlimited<ConsultationMessage[]>('GET', path, undefined, 30000);
|
|
}
|