Skip to content

Commit

Permalink
Cleanup discussed in code review #124
Browse files Browse the repository at this point in the history
  • Loading branch information
Xopabyteh committed Apr 11, 2024
1 parent 5aba870 commit fb01317
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace MensaGymnazium.IntranetGen3.DataLayer.Repositories;
public partial interface IStudentSubjectRegistrationRepository
{
public Task<List<StudentSubjectRegistration>> GetBySubjectAsync(
int id,
int subjectId,
CancellationToken cancellationToken = default);

//public Task<long> CountBySubjectAndTypeAsync(int subjectId, StudentRegistrationType type, CancellationToken cancellationToken = default);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ private async Task LoadStudentRegistrationAsync()
await StudentSubjectRegistrationsDataStore.EnsureDataAsync();
studentsRegistrationForThisSubject =
await StudentSubjectRegistrationsDataStore.GetByKeyOrDefaultAsync(SubjectId!.Value);

StateHasChanged();
}
private async Task HandleCancelRegistrationClicked()
{
Expand All @@ -49,7 +47,7 @@ private async Task HandleCancelRegistrationClicked()
await SubjectRegistrationsManagerFacade.CancelRegistrationAsync(Dto.FromValue(studentsRegistrationForThisSubject.Id));

// Invalidate data store
StudentSubjectRegistrationsDataStore.RegistrationsChanged();
StudentSubjectRegistrationsDataStore.Clear();

// Reload from cache (Xopa: maybe unnecessarily expensive?)
await LoadStudentRegistrationAsync();
Expand Down Expand Up @@ -77,7 +75,7 @@ await SubjectRegistrationsManagerFacade.CreateRegistrationAsync(
});

//Invalidate data store
StudentSubjectRegistrationsDataStore.RegistrationsChanged();
StudentSubjectRegistrationsDataStore.Clear();

// Reload from cache (Xopa: maybe unnecessarily expensive?)
await LoadStudentRegistrationAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,4 @@ namespace MensaGymnazium.IntranetGen3.Web.Client.Services.DataStores;

public interface IStudentSubjectRegistrationsDataStore : IDictionaryStaticDataStore<int, StudentSubjectRegistrationDto>
{
/// <summary>
/// Use this to invalidate the cache
/// </summary>
public void RegistrationsChanged();
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,12 @@ public StudentSubjectRegistrationsDataStore(IStudentSubjectRegistrationFacade st
}

protected override Func<StudentSubjectRegistrationDto, int> KeySelector => registration => registration.SubjectId!.Value;
protected override bool ShouldRefresh() => hasUnresolvedChanges;
protected override bool ShouldRefresh() => false; // Cleared by component causing changes

protected override async Task<IEnumerable<StudentSubjectRegistrationDto>> LoadDataAsync()
{
var dto = await studentSubjectRegistrationFacade.GetAllRegistrationsOfCurrentStudent();
hasUnresolvedChanges = false;

return dto ?? new();
}

private bool hasUnresolvedChanges = false;
public void RegistrationsChanged()
{
hasUnresolvedChanges = true;
}
}

0 comments on commit fb01317

Please sign in to comment.