Skip to content

refactor: adjust UpdateCardProgress to handle bulk update - #41

Merged
Dejmenek merged 5 commits into
mainfrom
40-refactor-updatecardprogress-to-handle-bulk-update
Sep 4, 2025
Merged

Dejmenek merged 5 commits into
mainfrom
40-refactor-updatecardprogress-to-handle-bulk-update

Conversation

@Dejmenek

@Dejmenek Dejmenek commented Sep 4, 2025

Copy link
Copy Markdown
Owner

Summary

This pull request refactors UpdateCardProgress for bulk updating card progress and enhances the database initialization process.

Changes

  • DataContext.cs: Added methods CreateTypes and CreateProcedures for database setup.
  • ICardsRepository.cs: Replaced UpdateCardProgress with UpdateCardsProgressBulkAsync for bulk updates.
  • CardsRepository.cs: Implemented the new bulk update logic using a stored procedure with a table-valued parameter.
  • CardProgressUpdateDto.cs: Introduced a new DTO class for encapsulating card progress update data.
  • SQL scripts: Removed UpdateCardProgress and added UpdateCardProgressBulk stored procedure along with new scripts for types and procedures.

Updated the ICardsRepository interface to remove the UpdateCardProgress method and introduce UpdateCardsProgressBulkAsync, which accepts an IEnumerable<CardProgressUpdateDto> for bulk updates. The CardsRepository implementation has been modified to use a SQL stored procedure for efficient bulk updates via a DataTable, enhancing performance by reducing the number of database calls. Logging and error handling have also been updated to reflect these changes.
Updated `DataContext.cs` to include new methods for creating database types and stored procedures. The `Init` method now calls `CreateTypes` and `CreateProcedures`, enhancing the database setup process.

Introduced a new stored procedure `UpdateCardProgressBulk` in `CreateStoredProcedures.sql` for bulk updating card progress using a table-valued parameter.

Modified `CreateTables.sql` to drop the `UpdateCardProgressBulk` procedure and several tables, ensuring a clean setup.

Updated `CreateTypes.sql` to drop and recreate the `CardProgressTVP` type with the necessary fields for card progress tracking.
A new class named `CardProgressUpdateDto` has been added to the `Flashcards.Models` namespace. This class includes three properties: `CardId`, `Box`, and `NextReviewDate`, which are essential for tracking the progress of flashcards in the application.
The SQL update statement that modified the `Box` and `NextReviewDate` fields in the `Cards` table has been removed. This change eliminates unnecessary code that was intended to update card details based on the card's `Id`.
Added new stored procedures and types in `SqlScripts.Designer.cs` to manage card progress in the flashcard application. Introduced `CreateStoredProcedures` and `CreateTypes` for bulk updates and new table types. Removed the `UpdateCardProgress` string and its corresponding SQL script, reflecting the updated functionality. Updated `SqlScripts.resx` to include new entries for the added procedures and types while removing the obsolete `UpdateCardProgress` entry.
@Dejmenek Dejmenek linked an issue Sep 4, 2025 that may be closed by this pull request
@Dejmenek
Dejmenek merged commit c235038 into main Sep 4, 2025
2 checks passed
@Dejmenek
Dejmenek deleted the 40-refactor-updatecardprogress-to-handle-bulk-update branch September 4, 2025 09:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Refactor UpdateCardProgress to handle bulk update

1 participant