Skip to content

Commit

Permalink
Fix #339: Included cache routine for Person check (#340) (#342)
Browse files Browse the repository at this point in the history
  • Loading branch information
antoineatstariongroup authored Mar 12, 2024
1 parent 0a99933 commit 67e1cb0
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions CDP4WebServices.API/Services/Authorization/PermissionService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// --------------------------------------------------------------------------------------------------------------------
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="PermissionService.cs" company="RHEA System S.A.">
// Copyright (c) 2015-2021 RHEA System S.A.
//
Expand Down Expand Up @@ -102,6 +102,12 @@ public class PermissionService : IPermissionService
/// </summary>
private List<Participant> currentParticipantCache;

/// <summary>
/// Gets the list of all <see cref="Participant" /> for any <see cref="Person"/> that are part of the same models than the current <see cref="Person"/> that is
/// reprsented by the current <see cref="Credentials" />
/// </summary>
private List<Participant> allAvailableParticipantCache;

/// <summary>
/// Determines whether the typeName can be read.
/// </summary>
Expand Down Expand Up @@ -632,14 +638,19 @@ private bool IsExcludedDomain(NpgsqlTransaction transaction, Thing thing)
private bool PersonIsParticipantWithinCurrentUserModel(NpgsqlTransaction transaction, Person person)
{
var participantsIds = this.Credentials.EngineeringModelSetups.SelectMany(x => x.Participant).ToArray();

if (participantsIds.Length == 0)
{
return false;
}

return this.ParticipantDao
.Read(transaction, SiteDirectory, participantsIds, true)
.Any(p => p.Person == person.Iid);
if (this.allAvailableParticipantCache == null || this.allAvailableParticipantCache.Count == 0)
{
this.allAvailableParticipantCache = this.ParticipantDao
.Read(transaction, SiteDirectory, participantsIds, true).ToList();
}

return this.allAvailableParticipantCache.Exists(p => p.Person == person.Iid);
}
}
}

0 comments on commit 67e1cb0

Please sign in to comment.