Fix #1 and added some comments for readability

This commit is contained in:
henry 2025-05-13 00:47:07 -04:00
parent a41daddb11
commit cf71bcbbc0
2 changed files with 7 additions and 0 deletions

View File

@ -57,6 +57,10 @@ namespace AccessQueueService.Data
var activeCutoff = now.AddSeconds(-activeSeconds); var activeCutoff = now.AddSeconds(-activeSeconds);
var numberOfActiveUsers = _accessTickets.Count(t => t.Value.ExpiresOn > now && t.Value.LastActive > activeCutoff); var numberOfActiveUsers = _accessTickets.Count(t => t.Value.ExpiresOn > now && t.Value.LastActive > activeCutoff);
var openSpots = capacityLimit - numberOfActiveUsers; var openSpots = capacityLimit - numberOfActiveUsers;
if(openSpots <= 0)
{
return true;
}
int filledSpots = 0; int filledSpots = 0;
while (filledSpots < openSpots && _nowServing < _nextUnusedTicket) while (filledSpots < openSpots && _nowServing < _nextUnusedTicket)
{ {

View File

@ -36,6 +36,7 @@ namespace AccessQueueService.Services
var existingTicket = _accessQueueRepo.GetTicket(userId); var existingTicket = _accessQueueRepo.GetTicket(userId);
if (existingTicket != null && existingTicket.ExpiresOn > DateTime.UtcNow) if (existingTicket != null && existingTicket.ExpiresOn > DateTime.UtcNow)
{ {
// Already has access
var expiresOn = existingTicket.ExpiresOn; var expiresOn = existingTicket.ExpiresOn;
if (ROLLING_EXPIRATION) if (ROLLING_EXPIRATION)
{ {
@ -54,6 +55,7 @@ namespace AccessQueueService.Services
} }
if (hasCapacity) if (hasCapacity)
{ {
// Doesn't have access, but there's space available
var accessTicket = new AccessTicket var accessTicket = new AccessTicket
{ {
UserId = userId, UserId = userId,
@ -68,6 +70,7 @@ namespace AccessQueueService.Services
} }
else else
{ {
// No access and no space, add to queue
var requestsAhead = _accessQueueRepo.GetRequestsAhead(userId); var requestsAhead = _accessQueueRepo.GetRequestsAhead(userId);
if (requestsAhead == -1) if (requestsAhead == -1)
{ {