Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ILookupGrain.AddOrUpdate does not what the function name says #8

Open
flensrocker opened this issue Apr 30, 2021 · 0 comments
Open

Comments

@flensrocker
Copy link

I'm playing around with Orleans and found your repository, because I was looking into managing Identities with Orleans.

I stumble across ILookupGrain.AddOrUpdate. It will never update a value, once it's in the dictionary.
If this is on purpose, shouldn't it be name just Add?

Otherwise, it should maybe do something like:

diff --git a/src/Orleans.IdentityStore/Grains/LookupGrain.cs b/src/Orleans.IdentityStore/Grains/LookupGrain.cs
index 1ef3f77..b094bb8 100644
--- a/src/Orleans.IdentityStore/Grains/LookupGrain.cs
+++ b/src/Orleans.IdentityStore/Grains/LookupGrain.cs
@@ -34,11 +34,11 @@ namespace Orleans.IdentityStore.Grains

         public async Task<bool> AddOrUpdate(string value, Guid grainKey)
         {
-            if (_index.State.Index.ContainsKey(value))
-                return false;
-
-            _index.State.Index[value] = grainKey;
-            await _index.WriteStateAsync();
+            if (!_index.State.Index.TryGetValue(value, out var oldGrainKey) || grainKey != oldGrainKey)
+            {
+                _index.State.Index[value] = grainKey;
+                await _index.WriteStateAsync();
+            }
             return true;
         }

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant