Skip to content

Commit

Permalink
fix: inverse semaphore count check
Browse files Browse the repository at this point in the history
Inverse the semaphore count check when waiting for a TMDB entity to be unlocked. In it's reversed state it will effectively skip the wait instead of waiting if the entity is locked, meaning it's doing the opposite of what we want.
  • Loading branch information
revam committed Jan 19, 2025
1 parent f1db5f2 commit 717f98c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions Shoko.Server/Providers/TMDB/TmdbMetadataService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2517,7 +2517,7 @@ private bool UpdateMovieExternalIDs(TMDB_Movie movie, ExternalIdsMovie externalI
private bool WaitIfEntityLocked(ForeignEntityType entityType, int id, string metadataKey)
{
var key = $"{entityType.ToString().ToLowerInvariant()}-{metadataKey}:{id}";
if (!_concurrencyGuards.TryGetValue(key, out var semaphore) || semaphore.CurrentCount == 0)
if (!_concurrencyGuards.TryGetValue(key, out var semaphore) || semaphore.CurrentCount != 0)
return false;

semaphore.Wait();
Expand All @@ -2530,7 +2530,7 @@ private Task<bool> WaitIfEntityLockedAsync(ForeignEntityType entityType, int id,
{
var startedAt = DateTime.Now;
var key = $"{entityType.ToString().ToLowerInvariant()}-{metadataKey}:{id}";
if (!_concurrencyGuards.TryGetValue(key, out var semaphore) || semaphore.CurrentCount == 0)
if (!_concurrencyGuards.TryGetValue(key, out var semaphore) || semaphore.CurrentCount != 0)
return Task.FromResult(false);

return semaphore.WaitAsync().ContinueWith(t =>
Expand Down

0 comments on commit 717f98c

Please sign in to comment.