✨ Add "Compare with past me" feature - #36
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a 'Compare with past self' feature, allowing users to compare their current GitHub contributions with their own data from a specified number of days ago. The implementation includes new menu items, localized strings, and logic to manage the mutual exclusivity of friend and past self comparisons. Feedback focuses on maintaining Swift style consistency regarding spacing and optimizing performance by avoiding redundant HTML parsing during data fetching.
| self.myContributes = contributeDataList | ||
| self.mystreaks = self.parseHtmltoDataForCount(html: html) | ||
| if self.friendUsername.isEmpty && self.selfCompareOffset > 0 { | ||
| self.friendContributes = self.parseHtmltoData(html: html, daysBack: self.selfCompareOffset) |
There was a problem hiding this comment.
This call triggers a redundant full parse of the HTML string using SwiftSoup. Note that the HTML is already parsed at line 569 (for contributeDataList) and again at line 574 (for mystreaks). Adding a third parse here significantly impacts performance, especially on slower connections or larger contribution graphs.
Consider refactoring parseHtmltoData to accept a pre-parsed Document or to return the full list of contribution data so that the caller can slice it as needed without re-parsing the entire document.
There was a problem hiding this comment.
Good catch. Addressed in 2a9f338 by extracting parseSortedDays(html:), which performs the SwiftSoup parse, sort, and tooltip injection once. parseHtmltoData and parseHtmltoDataForCount now take the pre-parsed [Element] and only slice/walk it. The HTML is parsed exactly once per fetch, regardless of whether self-compare is on. As a side effect, this also fixes the pre-existing 2-parse pattern (one for myContributes, one for mystreaks).
What does this PR do?
Adds a self-comparison option that mirrors the existing "compare with friend" feature, but the "friend" is yourself N days ago. Lets solo users see at a glance whether today is better or worse than yesterday (or 2 days ago, a week ago, etc.).
How it works
⌘P), prompts for an integer offset N (default 1, yesterday).UserDefaultskeyself_compare_offset(0= disabled, the default).Localization
enandkoLocalizable.stringsupdated with matching keys.Backward compatibility
Off by default. Users who don't enable it see no behavior change.
Screenshots
Compare with past me, offset = 1 (yesterday):
Compare with past me, offset = 2:
Default state, no friend, no self-compare:
Testing
Manually tested on macOS by the author across the four state combinations (off, self-compare on, friend on, switching between them). The repo has no test target today, so no unit tests are included to keep the diff focused. The new parsing helper is a small addition (a
daysBackparameter onparseHtmltoData) and is straightforward to cover later if a test target is added.