Skip to content

Commit

Permalink
fix: use set instead, preserve tokens during update
Browse files Browse the repository at this point in the history
  • Loading branch information
nunogois committed Nov 28, 2022
1 parent 2cdaf91 commit 59ee757
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib/services/api-token-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export class ApiTokenService {

private eventStore: IEventStore;

private lastSeenSecrets: string[] = [];
private lastSeenSecrets: Set<string> = new Set<string>();

private flagResolver: IFlagResolver;

Expand Down Expand Up @@ -110,9 +110,10 @@ export class ApiTokenService {
}

async updateLastSeen(): Promise<void> {
if (this.lastSeenSecrets.length > 0) {
await this.store.markSeenAt(this.lastSeenSecrets);
this.lastSeenSecrets = [];
if (this.lastSeenSecrets.size > 0) {
let toStore = new Set<string>();
[this.lastSeenSecrets, toStore] = [toStore, this.lastSeenSecrets];
await this.store.markSeenAt([...toStore]);
}
}

Expand Down Expand Up @@ -162,7 +163,7 @@ export class ApiTokenService {

if (token) {
if (this.flagResolver.isEnabled('tokensLastSeen')) {
this.lastSeenSecrets.push(token.secret);
this.lastSeenSecrets.add(token.secret);
}

return new ApiUser({
Expand Down

0 comments on commit 59ee757

Please sign in to comment.