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

Extract session ordinal logic to preference service #81

Merged
merged 1 commit into from
Nov 17, 2023

Conversation

fractalwrench
Copy link
Contributor

Goal

Extracts the business logic for incrementing the session number to the preference service. This means SessionHandler no longer needs knowledge about how the ordinal is calculated.

As far as the session number calculation goes, I think the implementation should be thread-safe. Starting a session is always synchronised with a lock, and that's the only place the function is called. Flushing the change to shared preferences is done using apply() which is async, but internally within the OS implementation the change is kept in an in-memory hashmap. The only two scenarios where the ordinal won't be incremented is if I/O fails before the process can terminate (e.g. due to a race), or if storage is wiped by a user (in which case a new device ID/ordinal is created).

Testing

Updated unit test coverage.

Copy link

codecov bot commented Nov 16, 2023

Codecov Report

Merging #81 (60f1de2) into master (8cfc0f0) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##           master      #81      +/-   ##
==========================================
- Coverage   76.03%   76.02%   -0.01%     
==========================================
  Files         313      313              
  Lines       10097    10095       -2     
  Branches     1455     1455              
==========================================
- Hits         7677     7675       -2     
  Misses       1832     1832              
  Partials      588      588              
Files Coverage Δ
...roid/embracesdk/prefs/EmbracePreferencesService.kt 90.14% <100.00%> (+0.06%) ⬆️
...ace/android/embracesdk/prefs/PreferencesService.kt 0.00% <ø> (ø)
...brace/android/embracesdk/session/SessionHandler.kt 87.71% <100.00%> (-0.22%) ⬇️

Copy link
Collaborator

@bidetofevil bidetofevil left a comment

Choose a reason for hiding this comment

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

LGTM.

Unrelated to this change, we should probably a similar counting for background activities (or account for background activities in this scheme... some how). I suspect we lose more of those than regular sessions given how much of an second-class citizen it seems to be.

@fractalwrench fractalwrench merged commit 503dde0 into master Nov 17, 2023
4 checks passed
@fractalwrench fractalwrench deleted the extract-session-number branch November 17, 2023 11:12
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.

None yet

2 participants