Fix #1 and added some comments for readability
This commit is contained in:
parent
a41daddb11
commit
cf71bcbbc0
|
@ -57,6 +57,10 @@ namespace AccessQueueService.Data
|
|||
var activeCutoff = now.AddSeconds(-activeSeconds);
|
||||
var numberOfActiveUsers = _accessTickets.Count(t => t.Value.ExpiresOn > now && t.Value.LastActive > activeCutoff);
|
||||
var openSpots = capacityLimit - numberOfActiveUsers;
|
||||
if(openSpots <= 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
int filledSpots = 0;
|
||||
while (filledSpots < openSpots && _nowServing < _nextUnusedTicket)
|
||||
{
|
||||
|
|
|
@ -36,6 +36,7 @@ namespace AccessQueueService.Services
|
|||
var existingTicket = _accessQueueRepo.GetTicket(userId);
|
||||
if (existingTicket != null && existingTicket.ExpiresOn > DateTime.UtcNow)
|
||||
{
|
||||
// Already has access
|
||||
var expiresOn = existingTicket.ExpiresOn;
|
||||
if (ROLLING_EXPIRATION)
|
||||
{
|
||||
|
@ -54,6 +55,7 @@ namespace AccessQueueService.Services
|
|||
}
|
||||
if (hasCapacity)
|
||||
{
|
||||
// Doesn't have access, but there's space available
|
||||
var accessTicket = new AccessTicket
|
||||
{
|
||||
UserId = userId,
|
||||
|
@ -68,6 +70,7 @@ namespace AccessQueueService.Services
|
|||
}
|
||||
else
|
||||
{
|
||||
// No access and no space, add to queue
|
||||
var requestsAhead = _accessQueueRepo.GetRequestsAhead(userId);
|
||||
if (requestsAhead == -1)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue