Skip to content

feat: rewrite caching system, use onScroll instead of onEndReached#21

Merged
melvin-qte merged 15 commits intomainfrom
fix/better-msgs-caching
Apr 30, 2025
Merged

feat: rewrite caching system, use onScroll instead of onEndReached#21
melvin-qte merged 15 commits intomainfrom
fix/better-msgs-caching

Conversation

@melvin-qte
Copy link
Copy Markdown
Collaborator

@melvin-qte melvin-qte commented Apr 29, 2025

ℹ️ Implementation details

Detail 1️⃣

This PR rewrites the caching system for messages.

🔴 Previously the subscriptions toward messages were setup the following way:

  • 1️⃣ One that fetches the latest 20 messages, which emptied cache on subscription
  • 2️⃣ One that fetches the latest 20 messages after a specified messageDoc

This meant that if a new message was added, the whole cache would be reset by 1️⃣, meaning that no messages would be persisted. This could lead to behavior such as user being scrolled down or interrupted in their reading if anyone sent messages parallel to their activity.

🟢 Now the subscriptions toward messages are setup the following way:

  • 1️⃣ One that fetches and subscribes to the latest 20 messages upon initialization, ignoring incoming messages, therefore staying static and only affected by deletion or modification of specified messages
  • 2️⃣ One that fetches and subscribes to messages after a specified messageDoc (previous messages)
  • 3️⃣ One that fetches and subscribes to messages that were created after the timestamp of the CuteChat intialization (only new messages)

Now no caching is emptied, but only accordingly updated based on the snapshot event changes, meaning the list will persist, and minimize the disruption for the user.

Detail 2️⃣

In this PR we also switch from using the onEndReached property for out list view, to instead determining this ourselves via the onScroll property to disabled the list itself triggering a refetch without using input.

@melvin-qte melvin-qte marked this pull request as ready for review April 30, 2025 09:43
@melvin-qte melvin-qte changed the base branch from main to beta April 30, 2025 09:43
@melvin-qte melvin-qte changed the base branch from beta to main April 30, 2025 09:44
@melvin-qte
Copy link
Copy Markdown
Collaborator Author

melvin-qte commented Apr 30, 2025

TODO:

  • Release to beta to test

Comment thread src/utils/docToMessage.ts Outdated
@melvin-qte melvin-qte requested a review from noahsvensson April 30, 2025 11:20
Comment thread src/utils/docToMessage.ts Outdated
}

const [files, sender] = await Promise.all([
new Promise<FirebaseFirestore.DocumentData | undefined>(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No need to create a new Promise anymore :D

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Fixed! ✅

Comment thread src/utils/docToMessage.ts Outdated
@melvin-qte melvin-qte requested a review from noahsvensson April 30, 2025 11:28
@melvin-qte melvin-qte merged commit 8344565 into main Apr 30, 2025
5 checks passed
@melvin-qte melvin-qte deleted the fix/better-msgs-caching branch April 30, 2025 11:31
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