fix: resolve 9 P0+P1 review findings (bills decorators, campus isolation bypass, ding raw crash, batch import counter, SSE multi-tab, interval leak, dept permissions, cycle prevention, tree depth)

This commit is contained in:
2026-07-06 00:38:51 +08:00
parent 90b6ce4aba
commit b3655da012
8 changed files with 75 additions and 6 deletions

View File

@@ -9,6 +9,7 @@ import { CreateNotificationDto } from './dto/notification.dto';
@Injectable()
export class NotificationsService {
private subjects = new Map<number, Subject<Notification>>();
private subscriberCounts = new Map<number, number>();
constructor(
@InjectRepository(Notification)
@@ -76,11 +77,20 @@ export class NotificationsService {
subscribe(userId: number): Observable<Notification> {
if (!this.subjects.has(userId)) {
this.subjects.set(userId, new Subject<Notification>());
this.subscriberCounts.set(userId, 0);
}
this.subscriberCounts.set(userId, (this.subscriberCounts.get(userId) ?? 0) + 1);
return this.subjects.get(userId)!.asObservable();
}
unsubscribe(userId: number): void {
const count = (this.subscriberCounts.get(userId) ?? 0) - 1;
if (count > 0) {
this.subscriberCounts.set(userId, count);
return;
}
// Last subscriber gone → complete + clean up
this.subscriberCounts.delete(userId);
const subj = this.subjects.get(userId);
if (subj) {
subj.complete();