Displaying targets weekly

We’ve implemented ‘weekly’ targets through code (seen below). However, CHWs have experienced inconsistent target count resetting.

Could caching be playing a role? Skimming through the Implications of Task Cache Expiration forum thread, it appears that targets are recalculated in two cases:

  1. When a contact changes.
  2. Cache expiry after 7 days

Perhaps they are also recalculated when a new month rolls over?

On Sunday evening we created items to increment the counts on all our targets. However, this Monday morning, all targets still displayed “1” despite the week having rolled over - even after logging out and back in:

We then edited the dwelling (item counted in top left), and the count reset to what we expected:

When editing the household, its report counts also reset as expected:

On what day does the 7-day cache expiry countdown start?
Is there a more user-friendly way to force recalculation?
Would supplying a date function make the target behave differently or trigger recalculation?

Dwelling weekly target:

{
    id: 'dwelling-registrations-weekly',
    icon: 'wcg-dwelling',
    translation_key: 'targets.dwelling.registration.weekly.count.title',
    type: 'count',
    goal: -1,
    date: 'reported',
    appliesTo: 'contacts',
    appliesToType: ['dwelling'],
    context: 'user.role === "chw" || user.contact_type === "chw"',
    appliesIf: passthrough(
      ({ contact: { reported_date, visit_date } }) => 
        visit_date ? isISOWithinWeek(visit_date) : isMilliWithinWeek(reported_date),
      ['Target: ', '[Weekly] Dwelling registration'],
      ['Reported date:', ({ contact: { reported_date } }) => reported_date],
      ['Visit date:', ({ contact: { visit_date } }) => visit_date]
    )
  },

Target extras Weekly exports:

isISOWithinWeek: (isoString) => isISOwithin('week', isoString),
isMilliWithinWeek: (milliseconds) => isMilliWithin('week', milliseconds),

Date calc methods:

function isWithin(unit, luxonDateTime) {
  const now = luxon.DateTime.now();
  const contains = luxon.Interval.fromDateTimes(now.startOf(unit), now.endOf(unit)).contains(luxonDateTime);

  return contains;
}

function isISOwithin(unit, isoString){
  return isWithin(unit, luxon.DateTime.fromISO(isoString));
}

function isMilliWithin(unit, milliseconds){
  return isWithin(unit, luxon.DateTime.fromMillis(milliseconds)); 
}