Fix Race conditions, thread-safety issues, and code quality in Developer Balance sample#751
Draft
Dhivya-SF4094 wants to merge 5 commits intodotnet:mainfrom
Draft
Fix Race conditions, thread-safety issues, and code quality in Developer Balance sample#751Dhivya-SF4094 wants to merge 5 commits intodotnet:mainfrom
Dhivya-SF4094 wants to merge 5 commits intodotnet:mainfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note
Are you waiting for the changes in this PR to be merged?
It would be very helpful if you could test the resulting artifacts from this PR and let us know in a comment if this change resolves your issue. Thank you!
This pull request introduces several important improvements to the data access layer and UI navigation logic of the DeveloperBalance application. The main focus is on making database initialization and table management thread-safe, optimizing queries to reduce database load, and improving code consistency and safety in navigation commands.
Description of Change
Updated
ClearTables()fromasync voidtoasync Taskand ensured it is properly awaited inLoadSeedDataAsync()to maintain correct execution order during seed initialization.Modified table drop logic in
SeedDataService.ClearTables()to execute sequentially instead of usingTask.WhenAll(). Now only_projectRepository.DropTableAsync()and_categoryRepository.DropTableAsync()are called, ensuring dependent tables are dropped exactly once.Renamed incorrectly named file
TaskRespository.cstoTaskRepository.csto align with class naming and maintain repository naming consistency.Introduced
SemaphoreSlim _initLockin all repositories and implemented a double-check locking pattern inInit()to ensure thread-safe initialization. UpdatedDropTableAsync()methods to execute under the same lock to prevent concurrent reset conditions.Optimized
ProjectRepository.ListAsync()by replacing per-project queries with bulk retrieval of tasks and tags, followed by in-memory grouping and assignment to projects.Removed unused
ProjectsTagsmodel class (Models/ProjectsTags.cs) that was not referenced anywhere in the codebase.Corrected SQL parameter usage in
TagRepository.ListAsync(int projectID)by adding the missing@prefix toProjectID.Updated
NavigateToProjectto returnTask.CompletedTaskwhen the project isnull, ensuring consistent asynchronous behavior.Added missing namespace declaration (
namespace DeveloperBalance.Data;) toJsonContext.csto align with project structure and maintain consistency.Updated
DisplaySnackbarAsyncandDisplayToastAsyncto useusing varwithCancellationTokenSource, ensuring proper disposal of resources.These changes collectively make the application more robust, efficient, and maintainable.
Issue Fixes
Fixes #748