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

feat: New user properties for Analytics [WPB-16121] #3312

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from

Conversation

borichellow
Copy link
Contributor

@borichellow borichellow commented Feb 25, 2025

TaskWPB-16121 [Android] Implement new user properties

What's new in this PR?

Need to implement new user properties 2 of them: amount of users contacts AND amount of team member in users team.

Solutions

  • Implement "caching" of users contacts and team size by saving values in MetaDataDao. That caches should refresh after 7 days.
  • added GetAnalyticsContactsDataUseCase for getting cached values and combining all the necessary data into AnalyticsContactsData data class
  • added UpdateContactsAmountsCacheUseCase for refreshing the cache and run it in UserSessionScope
  • added tests

Copy link
Contributor

github-actions bot commented Feb 26, 2025

Test Results

3 545 tests  +16   3 435 ✅ +16   6m 23s ⏱️ -15s
  605 suites + 2     110 💤 ± 0 
  605 files   + 2       0 ❌ ± 0 

Results for commit 96cfab5. ± Comparison against base commit db3bd82.

♻️ This comment has been updated with latest results.

Copy link
Contributor

@codecov-commenter
Copy link

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 50.76%. Comparing base (db3bd82) to head (96cfab5).

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #3312      +/-   ##
===========================================
+ Coverage    50.72%   50.76%   +0.03%     
===========================================
  Files         1610     1612       +2     
  Lines        58206    58317     +111     
  Branches      5255     5272      +17     
===========================================
+ Hits         29525    29603      +78     
- Misses       26649    26670      +21     
- Partials      2032     2044      +12     

see 7 files with indirect coverage changes


Continue to review full report in Codecov by Sentry.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update db3bd82...96cfab5. Read the comment docs.

@datadog-wireapp
Copy link

Datadog Report

Branch report: feat/new_user_properties_for_analytics
Commit report: ff7fd3c
Test service: kalium-jvm

✅ 0 Failed, 3435 Passed, 110 Skipped, 1m 4.1s Total Time

Copy link
Member

@MohamadJaara MohamadJaara left a comment

Choose a reason for hiding this comment

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

only one question about where to add the new functions

Comment on lines +614 to +641
override suspend fun getContactsAmountCached(): Either<StorageFailure, Int> = wrapStorageRequest {
metadataDAO.valueByKey(CONTACTS_AMOUNT_KEY)?.toInt()
}

override suspend fun getTeamMembersAmountCached(): Either<StorageFailure, Int> = wrapStorageRequest {
metadataDAO.valueByKey(TEAM_MEMBERS_AMOUNT_KEY)?.toInt()
}

override suspend fun setContactsAmountCached(amount: Int) =
metadataDAO.insertValue(CONTACTS_AMOUNT_KEY, amount.toString())

override suspend fun setTeamMembersAmountCached(amount: Int) =
metadataDAO.insertValue(TEAM_MEMBERS_AMOUNT_KEY, amount.toString())

override suspend fun getLastContactsDateUpdateDate(): Either<StorageFailure, Instant> = wrapStorageRequest {
metadataDAO.valueByKey(LAST_CONTACTS_UPDATE_KEY)?.let { Instant.parse(it) }
}

override suspend fun setContactsAmountCachingDate(date: Instant) =
metadataDAO.insertValue(LAST_CONTACTS_UPDATE_KEY, date.toString())

override suspend fun countContactsAmount(): Either<StorageFailure, Int> = wrapStorageRequest {
userDAO.countContactsAmount()
}

override suspend fun countTeamMembersAmount(): Either<StorageFailure, Int> = wrapStorageRequest {
userDAO.countTeamMembersAmount()
}
Copy link
Member

Choose a reason for hiding this comment

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

can those be moved out of the UserRepository to their own, maybe a AnalyticsRepo ?

Comment on lines +307 to +308
SELECT COUNT() FROM User WHERE User.team = (SELECT User.team FROM User WHERE User.qualified_id = (SELECT id FROM SelfUser))
AND qualified_id != (SELECT id FROM SelfUser);
Copy link
Member

Choose a reason for hiding this comment

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

a simple COUNT() FROM User WHERE User.team = :team_id and pass the team id form the cached one in the session scope, is a simpler way to do it

@@ -299,3 +299,10 @@ UPDATE User SET team = ? WHERE qualified_id = ?;
selectNameByMessageId:
SELECT name FROM User
WHERE qualified_id = (SELECT Message.sender_user_id FROM Message WHERE Message.id = :messageId AND Message.conversation_id = :conversationId);

selectContactsAmount:
SELECT COUNT() FROM User WHERE User.connection_status = 'ACCEPTED' AND qualified_id != (SELECT id FROM SelfUser);
Copy link
Member

Choose a reason for hiding this comment

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

same here there is no need to exclude self, just count accepted to make it simpler

@@ -299,3 +299,10 @@ UPDATE User SET team = ? WHERE qualified_id = ?;
selectNameByMessageId:
SELECT name FROM User
WHERE qualified_id = (SELECT Message.sender_user_id FROM Message WHERE Message.id = :messageId AND Message.conversation_id = :conversationId);

Copy link
Member

Choose a reason for hiding this comment

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

we would need to add index to the connection status in this case to support a wider range of use cases we can use

CREATE INDEX idx_user_connection_deleted_handle ON User (connection_status, deleted, handle);

this will make it also faster to do search 2 birds in 1 stone

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants