Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 5 additions & 9 deletions src/Orbit.Application/Common/CacheInvalidationHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@ public static class CacheInvalidationHelper
private static readonly string[] RetrospectivePeriods = ["week", "month", "quarter", "semester", "year"];
private static readonly string[] SummaryTimeBuckets = ["morning", "afternoon", "evening", "night", "timeless"];

public static void InvalidateSummaryCache(IMemoryCache cache, Guid userId)
public static void InvalidateSummaryCache(IMemoryCache cache, Guid userId, DateOnly today)
{
var nowAtUtc = DateTime.UtcNow;
var today = DateOnly.FromDateTime(nowAtUtc);
for (int i = -2; i <= 2; i++)
{
var date = today.AddDays(i);
Expand All @@ -28,10 +26,8 @@ public static void InvalidateSummaryCache(IMemoryCache cache, Guid userId)
/// changes habits, logs, or goals, otherwise users see a stale 1-hour-old retrospective
/// after logging or editing.
/// </summary>
public static void InvalidateRetrospectiveCache(IMemoryCache cache, Guid userId)
public static void InvalidateRetrospectiveCache(IMemoryCache cache, Guid userId, DateOnly today)
{
var nowAtUtc = DateTime.UtcNow;
var today = DateOnly.FromDateTime(nowAtUtc);
for (int i = -2; i <= 2; i++)
{
var date = today.AddDays(i);
Expand All @@ -56,10 +52,10 @@ public static void InvalidateGoalReviewCache(IMemoryCache cache, Guid userId)
/// Convenience: invalidate the summary, retrospective, and goal-review caches for a user. Use
/// this from any mutation command that affects habits, logs, or goals.
/// </summary>
public static void InvalidateUserAiCaches(IMemoryCache cache, Guid userId)
public static void InvalidateUserAiCaches(IMemoryCache cache, Guid userId, DateOnly today)
{
InvalidateSummaryCache(cache, userId);
InvalidateRetrospectiveCache(cache, userId);
InvalidateSummaryCache(cache, userId, today);
InvalidateRetrospectiveCache(cache, userId, today);
InvalidateGoalReviewCache(cache, userId);
}
}
11 changes: 4 additions & 7 deletions src/Orbit.Application/Goals/Commands/CreateGoalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,9 @@ public async Task<Result<Guid>> Handle(CreateGoalCommand request, CancellationTo
if (gateCheck.IsFailure)
return gateCheck.PropagateError<Guid>();

if (request.Deadline is { } deadline)
{
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
if (deadline < today)
return Result.Failure<Guid>(ErrorMessages.DeadlineInPast);
}
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
if (request.Deadline is { } deadline && deadline < today)
return Result.Failure<Guid>(ErrorMessages.DeadlineInPast);

var goalResult = Goal.Create(new Goal.CreateGoalParams(
request.UserId,
Expand Down Expand Up @@ -67,7 +64,7 @@ public async Task<Result<Guid>> Handle(CreateGoalCommand request, CancellationTo
LogGamificationGoalCreationFailed(logger, ex, request.UserId);
}

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(goal.Id);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Orbit.Application/Goals/Commands/DeleteGoalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DeleteGoalCommandHandler(
IGenericRepository<Goal> goalRepository,
IPayGateService payGate,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<DeleteGoalCommand, Result>
{
public async Task<Result> Handle(DeleteGoalCommand request, CancellationToken cancellationToken)
Expand All @@ -34,7 +35,8 @@ public async Task<Result> Handle(DeleteGoalCommand request, CancellationToken ca
goal.SoftDelete();
await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class LinkHabitsToGoalCommandHandler(
IGenericRepository<Habit> habitRepository,
IPayGateService payGate,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<LinkHabitsToGoalCommand, Result>
{
public async Task<Result> Handle(LinkHabitsToGoalCommand request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -54,7 +55,8 @@ public async Task<Result> Handle(LinkHabitsToGoalCommand request, CancellationTo

await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Orbit.Application/Goals/Commands/ReorderGoalsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public class ReorderGoalsCommandHandler(
IGenericRepository<Goal> goalRepository,
IPayGateService payGate,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<ReorderGoalsCommand, Result>
{
public async Task<Result> Handle(ReorderGoalsCommand request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -50,7 +51,8 @@ public async Task<Result> Handle(ReorderGoalsCommand request, CancellationToken

await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
4 changes: 3 additions & 1 deletion src/Orbit.Application/Goals/Commands/RestoreGoalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class RestoreGoalCommandHandler(
IGenericRepository<Goal> goalRepository,
IPayGateService payGate,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<RestoreGoalCommand, Result>
{
public async Task<Result> Handle(RestoreGoalCommand request, CancellationToken cancellationToken)
Expand All @@ -35,7 +36,8 @@ public async Task<Result> Handle(RestoreGoalCommand request, CancellationToken c
goal.Restore();
await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
11 changes: 4 additions & 7 deletions src/Orbit.Application/Goals/Commands/UpdateGoalCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
string Unit,
DateOnly? Deadline) : IRequest<Result>, IConcurrencyRetryable;

public partial class UpdateGoalCommandHandler(

Check warning on line 22 in src/Orbit.Application/Goals/Commands/UpdateGoalCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

Constructor has 8 parameters, which is greater than the 7 authorized.
IGenericRepository<Goal> goalRepository,
IGenericRepository<GoalProgressLog> progressLogRepository,
IPayGateService payGate,
Expand All @@ -35,12 +35,9 @@
if (gateCheck.IsFailure)
return gateCheck;

if (request.Deadline is { } deadline)
{
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
if (deadline < today)
return Result.Failure(ErrorMessages.DeadlineInPast);
}
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
if (request.Deadline is { } deadline && deadline < today)
return Result.Failure(ErrorMessages.DeadlineInPast);

var goal = await goalRepository.FindOneTrackedAsync(
g => g.Id == request.GoalId && g.UserId == request.UserId,
Expand All @@ -64,7 +61,7 @@
if (result.Value == GoalEditTransition.Completed)
await ProcessGoalCompletionSafeAsync(request.UserId, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@
decimal NewValue,
string? Note = null) : IRequest<Result>, IIdempotentCommand;

public partial class UpdateGoalProgressCommandHandler(

Check warning on line 17 in src/Orbit.Application/Goals/Commands/UpdateGoalProgressCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

Constructor has 8 parameters, which is greater than the 7 authorized.
IGenericRepository<Goal> goalRepository,
IGenericRepository<GoalProgressLog> progressLogRepository,
IPayGateService payGate,
IGamificationService gamificationService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache,
ILogger<UpdateGoalProgressCommandHandler> logger) : IRequestHandler<UpdateGoalProgressCommand, Result>

Check warning on line 25 in src/Orbit.Application/Goals/Commands/UpdateGoalProgressCommand.cs

View check run for this annotation

SonarQubeCloud / SonarCloud Code Analysis

Constructor has 8 parameters, which is greater than the 7 authorized.

See more on https://sonarcloud.io/project/issues?id=thomasluizon_orbit-api&issues=AZ9ZOrv3C_eeOFJVvH3R&open=AZ9ZOrv3C_eeOFJVvH3R&pullRequest=361
{
public async Task<Result> Handle(UpdateGoalProgressCommand request, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -57,7 +58,8 @@
if (justCompleted)
await ProcessGoalCompletionSafeAsync(request.UserId, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public partial class UpdateGoalStatusCommandHandler(
IPayGateService payGate,
IGamificationService gamificationService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache,
ILogger<UpdateGoalStatusCommandHandler> logger) : IRequestHandler<UpdateGoalStatusCommand, Result>
{
Expand Down Expand Up @@ -60,7 +61,8 @@ public async Task<Result> Handle(UpdateGoalStatusCommand request, CancellationTo
}
}

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ await unitOfWork.ExecuteInTransactionAsync(async ct =>
}
}, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, userToday);

return Result.Success(new BulkCreateResult(results));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class BulkDeleteHabitsCommandHandler(
IGenericRepository<Habit> habitRepository,
IUserStreakService userStreakService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<BulkDeleteHabitsCommand, Result<BulkDeleteResult>>
{
public async Task<Result<BulkDeleteResult>> Handle(BulkDeleteHabitsCommand request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -67,7 +68,8 @@ await ConcurrencyRetry.SaveWithRetryAsync(
}
}, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(new BulkDeleteResult(results));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ await ConcurrencyRetry.SaveWithRetryAsync(
}
}, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(new BulkLogResult(results));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ await unitOfWork.ExecuteInTransactionAsync(async ct =>
await unitOfWork.SaveChangesAsync(ct);
}, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(new BulkSkipResult(results));
}
Expand Down
5 changes: 3 additions & 2 deletions src/Orbit.Application/Habits/Commands/CreateHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ public async Task<Result<Guid>> Handle(CreateHabitCommand request, CancellationT
return slipAlertGate.PropagateError<Guid>();
}

var dueDate = request.DueDate ?? await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
var dueDate = request.DueDate ?? today;

if (opts.Days is { Count: > 0 } && !opts.Days.Contains(dueDate.DayOfWeek))
{
Expand Down Expand Up @@ -125,7 +126,7 @@ public async Task<Result<Guid>> Handle(CreateHabitCommand request, CancellationT
await ProcessGamificationSafeAsync(request.UserId, cancellationToken);
await ProcessOnboardingChecklistSafeAsync(request.UserId, OnboardingChecklistSignal.HabitCreated, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(habit.Id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public async Task<Result<Guid>> Handle(CreateSubHabitCommand request, Cancellati
await habitRepository.AddAsync(child, cancellationToken);
await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, userToday);

return Result.Success(childResult.Value.Id);
}
Expand Down
4 changes: 3 additions & 1 deletion src/Orbit.Application/Habits/Commands/DeleteHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public class DeleteHabitCommandHandler(
IGenericRepository<Habit> habitRepository,
IUserStreakService userStreakService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<DeleteHabitCommand, Result>
{
public async Task<Result> Handle(DeleteHabitCommand request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -43,7 +44,8 @@ await ConcurrencyRetry.SaveWithRetryAsync(
ct => userStreakService.RecalculateAsync(request.UserId, ct),
cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class DuplicateHabitCommandHandler(
IGenericRepository<HabitLog> habitLogRepository,
IPayGateService payGateService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<DuplicateHabitCommand, Result<Guid>>
{
public async Task<Result<Guid>> Handle(DuplicateHabitCommand request, CancellationToken cancellationToken)
Expand Down Expand Up @@ -61,7 +62,8 @@ public async Task<Result<Guid>> Handle(DuplicateHabitCommand request, Cancellati

await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success(rootCopy.Value.Id);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Orbit.Application/Habits/Commands/LogHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@
{
HabitLog unlogEntity;
LinkedGoalSyncResult goalSync;
for (var attempt = 1; ; attempt++)

Check warning on line 113 in src/Orbit.Application/Habits/Commands/LogHabitCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

This loop's stop incrementer updates 'attempt' but the stop condition doesn't test any variables.
{
var unlogResult = habit.Unlog(targetDate);
if (unlogResult.IsFailure)
Expand Down Expand Up @@ -140,7 +140,7 @@
async ct => streakState = await services.UserStreakService.RecalculateAsync(
habit.UserId, ct, awardFreezeIfEligible: false),
cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId, today);

return Result.Success(new LogHabitResponse(
unlogEntity.Id,
Expand All @@ -161,7 +161,7 @@
var shouldAdvanceDueDate = targetDate >= today;
HabitLog logEntity;
LinkedGoalSyncResult goalSync;
for (var attempt = 1; ; attempt++)

Check warning on line 164 in src/Orbit.Application/Habits/Commands/LogHabitCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

This loop's stop incrementer updates 'attempt' but the stop condition doesn't test any variables.
{
var logResult = habit.Log(targetDate, advanceDueDate: shouldAdvanceDueDate);
if (logResult.IsFailure)
Expand All @@ -179,7 +179,7 @@
}
catch (DbUpdateException ex) when (IsUniqueViolation(ex))
{
return await BuildAlreadyLoggedResultAsync(habit, targetDate, cancellationToken);
return await BuildAlreadyLoggedResultAsync(habit, targetDate, today, cancellationToken);
}
catch (DbUpdateConcurrencyException) when (attempt < MaxLogAttempts)
{
Expand All @@ -202,7 +202,7 @@
if (gamificationResult is null)
await PersistStreakRecalcAsync(request.UserId, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId, today);

await CheckReferralCompletionSafeAsync(request.UserId, cancellationToken);

Expand All @@ -226,7 +226,7 @@

private async Task PersistStreakRecalcAsync(Guid userId, CancellationToken cancellationToken)
{
for (var attempt = 1; ; attempt++)

Check warning on line 229 in src/Orbit.Application/Habits/Commands/LogHabitCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

This loop's stop incrementer updates 'attempt' but the stop condition doesn't test any variables.
{
try
{
Expand All @@ -242,7 +242,7 @@
}

private async Task<Result<LogHabitResponse>> BuildAlreadyLoggedResultAsync(
Habit habit, DateOnly targetDate, CancellationToken cancellationToken)
Habit habit, DateOnly targetDate, DateOnly today, CancellationToken cancellationToken)
{
var existingLogs = await repos.HabitLogRepository.FindAsync(
l => l.HabitId == habit.Id && l.Date == targetDate && l.Value > 0, cancellationToken);
Expand All @@ -251,7 +251,7 @@
var users = await repos.UserRepository.FindAsync(u => u.Id == habit.UserId, cancellationToken);
var currentStreak = users.SingleOrDefault()?.CurrentStreak ?? 0;

CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId, today);

return Result.Success(new LogHabitResponse(
winningLog.Id,
Expand Down
4 changes: 3 additions & 1 deletion src/Orbit.Application/Habits/Commands/RestoreHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class RestoreHabitCommandHandler(
IGenericRepository<Habit> habitRepository,
IUserStreakService userStreakService,
IUnitOfWork unitOfWork,
IUserDateService userDateService,
IMemoryCache cache) : IRequestHandler<RestoreHabitCommand, Result>
{
public async Task<Result> Handle(RestoreHabitCommand request, CancellationToken cancellationToken)
Expand All @@ -42,7 +43,8 @@ await ConcurrencyRetry.SaveWithRetryAsync(
ct => userStreakService.RecalculateAsync(request.UserId, ct),
cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
4 changes: 2 additions & 2 deletions src/Orbit.Application/Habits/Commands/SkipHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
Guid HabitId,
DateOnly? Date = null) : IRequest<Result>, IConcurrencyRetryable, IIdempotentCommand;

public partial class SkipHabitCommandHandler(

Check warning on line 21 in src/Orbit.Application/Habits/Commands/SkipHabitCommand.cs

View workflow job for this annotation

GitHub Actions / SonarCloud Analysis

Constructor has 8 parameters, which is greater than the 7 authorized.
IGenericRepository<Habit> habitRepository,
IGenericRepository<HabitLog> habitLogRepository,
IGenericRepository<Goal> goalRepository,
Expand Down Expand Up @@ -68,7 +68,7 @@
if (anyGoalJustCompleted)
await ProcessGoalCompletionSafeAsync(habit.UserId, cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId, today);

return Result.Success();
}
Expand All @@ -77,7 +77,7 @@
{
habit.PostponeTo(today.AddDays(1));
await unitOfWork.SaveChangesAsync(cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, habit.UserId, today);
return Result.Success();
}

Expand Down
3 changes: 2 additions & 1 deletion src/Orbit.Application/Habits/Commands/UpdateHabitCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public async Task<Result> Handle(UpdateHabitCommand request, CancellationToken c

await unitOfWork.SaveChangesAsync(cancellationToken);

CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId);
var today = await userDateService.GetUserTodayAsync(request.UserId, cancellationToken);
CacheInvalidationHelper.InvalidateUserAiCaches(cache, request.UserId, today);

return Result.Success();
}
Expand Down
Loading
Loading