Skip to content

Commit

Permalink
Merge pull request #40 from episerver/bugfix/MAR-1671-ABTesting-data-…
Browse files Browse the repository at this point in the history
…is-counted-incorrectly

Fix ProxyEventHandler added multiple time
  • Loading branch information
Tson-optimizely authored Jul 31, 2023
2 parents 92c02c0 + 4e221f0 commit d340892
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ public interface IReferenceCounter
void RemoveReference(object src);
Boolean hasReference(object src);
int getReferenceCount(object src);
bool IsNullOrEmpty();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ public int getReferenceCount(object src)
dictionary.TryGetValue(src, out value);
return value;
}

public bool IsNullOrEmpty() {
return dictionary is null || (dictionary.Count == 0);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ internal void AddProxyEventHandler(IKpi kpi)

// Add the proxyeventhandler only once, if its in our reference counter, just increment
// the reference.
if (!_ReferenceCounter.hasReference(kpi.GetType()))
if (_ReferenceCounter.IsNullOrEmpty())
{
kpi.EvaluateProxyEvent += ProxyEventHandler;
_ReferenceCounter.AddReference(kpi.GetType());
Expand All @@ -689,7 +689,7 @@ internal void RemoveProxyEventHandler(IKpi kpi)
_ReferenceCounter.RemoveReference(kpi.GetType());

// Remove the proxyeventhandler only once, when the last reference is removed.
if (!_ReferenceCounter.hasReference(kpi.GetType()))
if (_ReferenceCounter.IsNullOrEmpty())
{
kpi.EvaluateProxyEvent -= ProxyEventHandler;
}
Expand Down

0 comments on commit d340892

Please sign in to comment.