Skip to content

Comments

Cache authors dict#2

Merged
timvink merged 4 commits intotimvink:masterfrom
uliska:cache-authors
Feb 26, 2020
Merged

Cache authors dict#2
timvink merged 4 commits intotimvink:masterfrom
uliska:cache-authors

Conversation

@uliska
Copy link
Contributor

@uliska uliska commented Feb 24, 2020

This is basically a warm-up PR to get familiar with the code.

it includes one fix (second commit) and one (perceived) coding improvement (third commit). The initial whitespace commit is only to have the following commits clean.

(I don't intend to be nitpicking about whitespace,
but without a separate commit the following commits
would become dirty).
The "authors" return value should be a list (of author dicts),
but in case of failure it returned an empty string.

This was incorrectly handled in Util.summarize(), but
fortunately with no negative effect:
- iterating over a string returns its characters, but
- iterating over an empty string behaves like
  iterating over an empty dict.
Create a cache dictionary, with file paths as key.
Util.get_authors() is called twice, and there's no need
to call Git twice if we can cache the results.
This has been inadvertently been overwritten by copy/paste
This was referenced Feb 24, 2020
total_lines = sum([x.get('lines') for x in authors])
for author in authors:
author['contribution'] = self._format_perc(author['lines'] / total_lines)
if not authors:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early stopping is a better design pattern that's easier to read, i.e

if authors:
   return authors

# rest of the code
return authors

@timvink
Copy link
Owner

timvink commented Feb 26, 2020

Thanks @uliska !

@timvink timvink merged commit f3f2d19 into timvink:master Feb 26, 2020
@uliska uliska deleted the cache-authors branch March 5, 2020 11:32
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

Successfully merging this pull request may close these issues.

2 participants