I want to dynamically track usersā āstreaksā (specifcally, the current number of consecutive days in which theyāve performed any of a few different actions in-app; Iāll call them ālogsā for simplicty).
Iāve tried a number of solutions, and nothing is reliable, so far.
Currently, I am using a recursive backend workflow (calculate-streak) that checks one day at a time, moving backward from today.
-
If a log exists for the day, it continues checking the previous day.
-
If no log exists, it stops and saves the streak count.
-
A key variable here is that a user who signed up 10 days ago may have a current streak of 2, but is allowed to go back in time and log for previous days to recover their streak. (itās a food logging app that allows you to log a meal with a photo, so itās certainly conceivable that user would have a photo from a previous day).
My hope was to avoid doing complex list math and/or client-side looping.
It is triggered on page load AND when a new ālogā is created.
| Parameter | Type | Purpose |
|---|---|---|
user |
User | whose streak weāre counting |
day |
date | today at midnight (used as a fixed āanchorā) |
offset |
number | how many days back weāre checking (starts at 0) |
current-streak |
number | how many consecutive days found so far (starts at 0) |
max-days |
number | safety limit for recursion (e.g., 365) |
There are two mutually exclusive steps in the workflow.
Branch A - Log Exists:
-
Condition:
Search for NutriTrackers:count > 0 and offset < max-days -
Action: Schedule
calculate-streakagain with:-
offset = offset + 1 -
current-streak = current-streak + 1
-
Keeps counting backward.
Branch B - No Log Found:
-
Condition:
Search for NutriTrackers:count = 0 -
Action: Make changes to
User:streak = current-streak
Stops recursion and saves the total streak.
The issue is basically that this almost never works as expected. Very surprisingly sometimes it will. As I mentioned, Iāve tried other approaches, but nothing has worked yet.
If you see an obvious fatal flaw in my logic above, please advise. Alternatively, if you can think of a better way, please share. This feels like it ought to be MUCH simpler than this!
Help, advice, anything at all is greatly appreciated ![]()
The fire icon is where I want to display the usersā streak. So simple, right? ![]()




