DEV Community

friendship
friendship

Posted on

Shipaton: Do0ne Build Journal #5 - Social Feature: Discover Goals & Tasks

Image Do0ne development at the 24-hour café “The November.”

Objective

  • Implement a feature that allows users to view other people’s Goals and Do0ne items.
  • Provide a Like feature to cheer for each Goal.

Implementation Plan

  1. Add a Discover menu to display other users’ Goals and Do0ne lists.
  2. Add a field in each Goal document to store the number of Likes.
  3. Create a Likes subcollection under each Goal to track which users pressed Like.
  4. Restrict Likes to once per day per user.
  5. Add a Likers subcollection to record each user’s Like history (when and how many times).

Problem

  • If one Goal has 20 Do0ne items and a user has 100 Goals, one full read requires 21 × 100 = 2,100 Firestore Reads.
  • If 10 users perform this action, it results in 21,000 Reads, which is too costly.

Solution

  1. Run a Cloud Function on a schedule to generate snapshot JSON files containing Goals and Do0ne data.
  2. FlutterFlow will load these JSON snapshots via API calls instead of reading directly from Firestore.
  3. This reduces Firestore Reads since users fetch pre-generated JSON instead of live documents.
  4. Some information still requires real-time updates:
  5. Like count and whether the current user has Liked must be up-to-date.
  6. Therefore, Firestore is read only when a Goal is displayed to fetch its latest Like data.

Image JSON snapshot file generated from Goal and Do0ne data

FlutterFlow Implementation

  1. Create an API call to load the snapshot JSON file.
  2. Bind the API response to a PageView, generating Goal pages dynamically.
  3. When a PageView page becomes active, fetch the latest Like data from Firestore for that Goal.
  4. Implement Like / Unlike functionality.

Actual Implementation

  1. Fetching Goal data only when a PageView becomes active didn’t work reliably, so the entire dataset is now loaded when the PageView is first created.
  2. This eliminated the Read-saving advantage, so pagination was introduced when generating snapshots: each JSON file contains only 10 Goals.
  3. When the user reaches the last PageView page, the app requests the next snapshot API and appends the new pages dynamically.

View Likes on my Goal from others
Image View Likes on my Goal from others

Discover lets you see others’ Goals and Do0ne and cheer them on with Likes
Image Discover lets you see others’ Goals and Do0ne and cheer them on with Likes

Top comments (0)