courseStudentRosterRefreshProvider top-level property

FutureProviderFamily<CourseISchoolRefreshResult, CourseISchoolKey> courseStudentRosterRefreshProvider
final

Refreshes a roster only when its timestamp is missing or stale.

Keeping refresh separate from the cache stream lets the UI retain cached students while also reacting to a failed background refresh.

Implementation

final courseStudentRosterRefreshProvider = FutureProvider.autoDispose
    .family<CourseISchoolRefreshResult, CourseISchoolKey>(
      retry: (_, _) => null,
      (ref, key) async {
        final keepAlive = ref.keepAlive();
        try {
          final repository = ref.watch(courseRepositoryProvider);
          final hadCacheAtStart =
              (await repository.watchStudentRoster(key.courseOfferingId).first)
                  .fetchedAt !=
              null;
          if (await repository.isStudentRosterFresh(key.courseOfferingId)) {
            return (refreshed: false, hadCacheAtStart: hadCacheAtStart);
          }
          await repository.refreshStudentRoster(
            courseOfferingId: key.courseOfferingId,
            courseNumber: key.courseNumber,
          );
          return (refreshed: true, hadCacheAtStart: hadCacheAtStart);
        } finally {
          keepAlive.close();
        }
      },
    );