Skip to content

feat: Add Jetpack Paging 3 support for messages and threads/contacts#3795

Merged
jamesarich merged 8 commits into
meshtastic:mainfrom
mdecourcy:perf/paginate-db-queries
Nov 24, 2025
Merged

feat: Add Jetpack Paging 3 support for messages and threads/contacts#3795
jamesarich merged 8 commits into
meshtastic:mainfrom
mdecourcy:perf/paginate-db-queries

Conversation

@mdecourcy

Copy link
Copy Markdown
Contributor

Summary

  • Implement pagination for message threads (50 items per page)
  • Implement pagination for contact/conversation list (30 items per page)
  • Maintain all existing features: unread tracking, auto-scroll, reactions, selection mode
  • Use hybrid approach: pagination for bulk data + lightweight metadata queries for features

Performance Benefits

  • Reduced memory usage for large message histories
  • Faster initial load times
  • Lazy loading when scrolling through old messages
  • Better performance with many contacts/conversations

Technical Details

  • Added Jetpack Paging 3 library (androidx.paging:paging-runtime:3.3.5)
  • Created getMessagesFromPaged() and getContactsPaged() in database layer
  • Implemented MessageListPaged.kt composable with full feature parity
  • Removed non-paged message implementation after migration
  • Kept non-paged contact list for ShareScreen (simple picker doesn't need pagination)

@jamesarich

Copy link
Copy Markdown
Collaborator

looks good to go when cleaned up and rebased 👍

@mdecourcy mdecourcy force-pushed the perf/paginate-db-queries branch 2 times, most recently from d654c31 to f86ec72 Compare November 23, 2025 23:06
mdecourcy and others added 2 commits November 23, 2025 15:17
Exactly matches upstream's logic:
- Track remoteMessageCount to restart effect when remote messages arrive
- Find oldest unread message (lastUnreadIndex)
- Mark it when scrolled past, which batches all newer messages via SQL

The SQL 'WHERE received_time <= timestamp' marks all messages with
timestamp <= the oldest unread, effectively batching all newer unreads.
Fixes race condition while maintaining batch marking behavior.
Changed logic to mark the first (newest) visible unread message instead of
the last (oldest). Since newer messages have HIGHER timestamps, the SQL
query `WHERE received_time <= :timestamp` will batch-mark all older unread
messages when we pass the newest visible unread's timestamp.

This combines both fixes:
- Race condition: LaunchedEffect restarts when remoteMessageCount changes
- Batch marking: Marks all visible unreads at once instead of one at a time

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@mdecourcy mdecourcy marked this pull request as ready for review November 23, 2025 23:23
Only mark messages as read after user has interacted with the list
(scrolling or changing scroll position), preventing notifications from
being cleared before the user has actually viewed the messages.
Handle case where all unread messages are visible on screen without
needing to scroll. The debounce now triggers 3 seconds after the list
settles (either after scroll stops OR after initial load), ensuring
messages get marked as read in both scrolling and no-scroll scenarios.
@jamesarich jamesarich added this pull request to the merge queue Nov 24, 2025
Merged via the queue into meshtastic:main with commit 5e8c979 Nov 24, 2025
5 checks passed
@codecov

codecov Bot commented Nov 24, 2025

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 251 lines in your changes missing coverage. Please review.
✅ Project coverage is 0.55%. Comparing base (5d61e78) to head (a89125a).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
...g/meshtastic/feature/messaging/MessageListPaged.kt 0.00% 91 Missing ⚠️
...in/java/com/geeksville/mesh/ui/contact/Contacts.kt 0.00% 74 Missing ⚠️
...kotlin/org/meshtastic/feature/messaging/Message.kt 0.00% 31 Missing ⚠️
...om/geeksville/mesh/ui/contact/ContactsViewModel.kt 0.00% 30 Missing ⚠️
...eshtastic/core/data/repository/PacketRepository.kt 0.00% 17 Missing ⚠️
...g/meshtastic/feature/messaging/MessageViewModel.kt 0.00% 8 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##            main   #3795      +/-   ##
========================================
- Coverage   0.56%   0.55%   -0.01%     
========================================
  Files        381     381              
  Lines      21738   21852     +114     
  Branches    2683    2704      +21     
========================================
  Hits         122     122              
- Misses     21596   21710     +114     
  Partials      20      20              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@jamesarich jamesarich added this to the 2.7.8 milestone Nov 26, 2025
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