Skip to content

Conversation

@rapterjet2004
Copy link
Contributor

@rapterjet2004 rapterjet2004 commented Dec 9, 2025

The getOpenConversations API endpoint was being called every time the user gets a list of rooms, which was very inefficient, considering how often that occurs. This PR, moves that functionality to the querying logic, while also refactoring the querying logic for clarity and correctness.

Now every time you search, it launches a Coroutine that gets the open conversations/users with structured concurrency, and processes their data in a thread safe way, before retrieving the messages async and adding them to the adapter when ready.

🚧 TODO

  • Figure out why users appear when tapping the search bar initially
  • Clicking load more doesn't remove the refresh indicator
  • Test this out with filtering button

🏁 Checklist

  • ⛑️ Tests (unit and/or integration) are included or not needed
  • 🔖 Capability is checked or not needed
  • 🔙 Backport requests are created or not needed: /backport to stable-xx.x
  • 📅 Milestone is set
  • 🌸 PR title is meaningful (if it should be in the changelog: is it meaningful to users?)

@rapterjet2004 rapterjet2004 self-assigned this Dec 9, 2025
@rapterjet2004 rapterjet2004 added the 2. developing Work in progress label Dec 9, 2025
@rapterjet2004 rapterjet2004 marked this pull request as ready for review December 11, 2025 17:44
@rapterjet2004 rapterjet2004 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 11, 2025
@rapterjet2004 rapterjet2004 requested review from mahibi and sowjanyakch and removed request for mahibi and sowjanyakch December 11, 2025 17:45
@rapterjet2004 rapterjet2004 added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Dec 11, 2025
@rapterjet2004 rapterjet2004 added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Dec 11, 2025
@rapterjet2004 rapterjet2004 force-pushed the issue-5629-fix-inefficient-calls branch from 1ffff21 to def020f Compare December 12, 2025 16:19
- dealing with race conditions b/c the code was structured weirdly

- contacts view model fetches users on init for some reason, this is a work around

- coroutines should always throw cancellation exception

Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
Signed-off-by: rapterjet2004 <juliuslinus1@gmail.com>
@rapterjet2004 rapterjet2004 force-pushed the issue-5629-fix-inefficient-calls branch from def020f to 7b3f24d Compare December 15, 2025 15:39
@github-actions
Copy link
Contributor

APK file: https://www.kaminsky.me/nc-dev/android-artifacts/5630.apk

qrcode

To test this change/fix you can simply download above APK file and install and test it in parallel to your existing Nextcloud app.

@github-actions
Copy link
Contributor

Codacy

Lint

TypemasterPR
Warnings9999
Errors00

SpotBugs

CategoryBaseNew
Bad practice66
Correctness1010
Dodgy code5454
Internationalization33
Malicious code vulnerability33
Performance44
Security11
Total8181

Copy link
Collaborator

@mahibi mahibi left a comment

Choose a reason for hiding this comment

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

I approve as it solves the issue. 👍

But we should solve that in a different way in a follow up PR:

A better solution (but not for this PR) will be to move the fetching into the viewModel and there we should make use of combine to combine different data sources.
This should be done in general throughout the app and not only for this scenario.
Using async + awaitAll is not necessary then and also mutex handling is not needed.

So in the viewModel there should be code like:

viewModelScope.launch {
    combine(
        repository.fetchUsersFlow(filter),
        repository.fetchOpenConversationsFlow(filter)
    ) { users, conversations ->
        users + conversations
    }.collect { combined ->
        _searchResults.value = combined
    }
}

So in general, move more logic to view model while keeping the UI "dumb". The UI should only get the ready to use data for displaying..
We should make use of combine in many places which will also reduce boilerplate and complex code as we use too many flows that emit to the UI's.
Using combine will avoid to have too many flows.
Having too many flows makes code hard to read and it's hard to keep track where something is catched and what happens.

@mahibi mahibi merged commit 597cd88 into master Dec 16, 2025
18 of 19 checks passed
@mahibi mahibi deleted the issue-5629-fix-inefficient-calls branch December 16, 2025 12:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch open conversations only when searching

3 participants