Fix race conditions and GH API endpoints #100
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was investigating, why most of the stats in the overview image were
0
lately.Turns out, there was a race condition in the properties awaiting
get_stats()
.All of these properties would check a field that is supposed to be filled by
get_stats()
and if it wasNone
, they would await the result ofget_stats()
. However, since these fields were set to empty values (e.g.dict()
) at the beginning ofget_stats()
, some of the async properties ofStats
would return these empty values beforeget_stats()
was actually completed, resulting in lots of zeros in the generated images :)So what I changed is this:
Stats._lines_changed
,Stats._name
...) at the end ofget_stats()
rather than the beginningget_stats()
to be completed, by introducing anasyncio.Event
and wrappingget_stats
in a function that ensures it is only called once and otherwise awaits the event.This is the relevant code:
So
get_stats
was renamed to_get_stats
. The new functionget_stats
checks if the eventStats._get_stats_completed
already exists. If not, it creates it and starts the wrapped function_get_stats
, awaits it and then sets the event. If the event already exists, it just waits for it to be set.