Skip to content

Commit

Permalink
chore: Remove unneeded name lookup (#1781)
Browse files Browse the repository at this point in the history
## Description

GetCurrentUserInformation performs a name lookup which isn't used in
search, causing a needless lookup to Registry (and Altinn 2) for
searches. Also, moves the current user name lookup in Get to be
performed after all early returns to avoid doing it needlessly.

## Related Issue(s)

- N/A

## Verification

- [x] **Your** code builds clean without any errors or warnings
- [x] Manual testing done (required)
  • Loading branch information
elsand authored Feb 3, 2025
1 parent 5b61dda commit 3cbdc9d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ public GetDialogQueryHandler(

public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationToken cancellationToken)
{
var currentUserInformation = await _userRegistry.GetCurrentUserInformation(cancellationToken);

// This query could be written without all the includes as ProjectTo will do the job for us.
// However, we need to guarantee an order for sub resources of the dialog aggregate.
// This is to ensure that the get is consistent, and that PATCH in the API presentation
Expand Down Expand Up @@ -120,6 +118,7 @@ public async Task<GetDialogResult> Handle(GetDialogQuery request, CancellationTo

// TODO: What if name lookup fails
// https://github.com/altinn/dialogporten/issues/387
var currentUserInformation = await _userRegistry.GetCurrentUserInformation(cancellationToken);
dialog.UpdateSeenAt(
currentUserInformation.UserId.ExternalIdWithPrefix,
currentUserInformation.UserId.Type,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,6 @@ public SearchDialogQueryHandler(

public async Task<SearchDialogResult> Handle(SearchDialogQuery request, CancellationToken cancellationToken)
{
var currentUserInfo = await _userRegistry.GetCurrentUserInformation(cancellationToken);

var searchExpression = Expressions.LocalizedSearchExpression(request.Search, request.SearchLanguageCode);
var authorizedResources = await _altinnAuthorization.GetAuthorizedResourcesForSearch(
request.Party ?? [],
Expand Down Expand Up @@ -187,7 +185,7 @@ public async Task<SearchDialogResult> Handle(SearchDialogQuery request, Cancella

foreach (var seenLog in paginatedList.Items.SelectMany(x => x.SeenSinceLastUpdate))
{
seenLog.IsCurrentEndUser = IdentifierMasker.GetMaybeMaskedIdentifier(currentUserInfo.UserId.ExternalIdWithPrefix) == seenLog.SeenBy.ActorId;
seenLog.IsCurrentEndUser = IdentifierMasker.GetMaybeMaskedIdentifier(_userRegistry.GetCurrentUserId().ExternalIdWithPrefix) == seenLog.SeenBy.ActorId;
}

return paginatedList.ConvertTo(_mapper.Map<DialogDto>);
Expand Down

0 comments on commit 3cbdc9d

Please sign in to comment.