Skip to content

Commit 44682ca

Browse files
committed
fix deletekey async
1 parent ba01e73 commit 44682ca

1 file changed

Lines changed: 15 additions & 12 deletions

File tree

OpenFlow/src/DBHelper.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ export class DBHelper {
8080
public async DeleteKey(key) {
8181
this.init();
8282
Logger.instanse.debug("DBHelper", "DeleteKey", "Remove from cache : " + key);
83-
this.memoryCache.del(key);
83+
await this.memoryCache.del(key);
8484
}
8585
public item_cache: BaseObserver = null;
8686
public ensureotel() {
@@ -333,7 +333,7 @@ export class DBHelper {
333333
let item = await this.memoryCache.wrap("username_" + username, () => {
334334
if (jwt === null || jwt == undefined || jwt == "") { jwt = Crypt.rootToken(); }
335335
Logger.instanse.debug("DBHelper", "FindByUsername", "Add user to cache : " + username);
336-
return Config.db.getbyusername<User>(username, jwt, true, span);
336+
return Config.db.getbyusername<User>(username, null, jwt, true, span);
337337
});
338338
if (NoderedUtil.IsNullUndefinded(item)) return null;
339339
return this.DecorateWithRoles(User.assign(item), span);
@@ -344,23 +344,25 @@ export class DBHelper {
344344
Logger.otel.endSpan(span);
345345
}
346346
}
347-
public async FindByUsernameOrId(username: string, id: string, parent: Span): Promise<User> {
347+
public async FindByUsernameOrFederationid(username: string, issuer: string, parent: Span): Promise<User> {
348348
this.init();
349-
const span: Span = Logger.otel.startSubSpan("dbhelper.FindByUsernameOrId", parent);
349+
const span: Span = Logger.otel.startSubSpan("dbhelper.FindByUsername", parent);
350350
try {
351-
var user = await this.FindById(id, null, span);
352-
if (user == null) user = await this.FindByUsername(username, null, span);
353-
return user;
351+
if (NoderedUtil.IsNullEmpty(username)) return null;
352+
let item = await this.memoryCache.wrap("federation_" + username, () => {
353+
const jwt = Crypt.rootToken();
354+
Logger.instanse.debug("DBHelper", "FindByUsername", "Add user to cache : " + username);
355+
return Config.db.getbyusername<User>(username, issuer, jwt, true, span);
356+
});
357+
if (NoderedUtil.IsNullUndefinded(item)) return null;
358+
return this.DecorateWithRoles(User.assign(item), span);
354359
} catch (error) {
355360
span?.recordException(error);
356361
throw error;
357362
} finally {
358363
Logger.otel.endSpan(span);
359364
}
360-
}
361-
public async FindByUsernameOrFederationid(username: string, parent: Span): Promise<User> {
362-
var result = await this.FindByUsername(username, null, parent);
363-
return result;
365+
364366
}
365367
public async DecorateWithRoles<T extends TokenUser | User>(user: T, parent: Span): Promise<T> {
366368
this.init();
@@ -534,7 +536,8 @@ export class DBHelper {
534536
const span: Span = Logger.otel.startSubSpan("dbhelper.ensureUser", parent);
535537
try {
536538
span?.addEvent("FindByUsernameOrId");
537-
let user: User = await this.FindByUsernameOrId(username, id, span);
539+
let user = await this.FindById(id, null, span);
540+
if (user == null) user = await this.FindByUsername(username, null, span);
538541
if (user !== null && (user._id === id || id === null)) { return user; }
539542
if (user !== null && id !== null) {
540543
span?.addEvent("FindByUsernameOrId");

0 commit comments

Comments
 (0)