-
Notifications
You must be signed in to change notification settings - Fork 75
Added: Replace Library Items Atomically in Place & Other Library Refactorings #3199
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Sewer56
wants to merge
13
commits into
main
Choose a base branch
from
replace-mod-in-place-v2
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
6a2ccf9
Added: LoadoutsWithLibraryItem API
Sewer56 29041a6
Improve: Unify all loadout addition/removal logic across the App into…
Sewer56 960fabe
Removed: Unused monitor in LibraryService
Sewer56 dbfc6a2
Chore: Miscellaneous Cleanup
Sewer56 919bcb1
Replace Multiple Mods in Transactional Manner
Sewer56 700fb96
Improved: Optimized Readonly Collection Check
Sewer56 dde204d
Improve: Reduce unnecessary boxing by not reusing the IEnumerable ove…
Sewer56 e385d8f
Added: Test for filtering out item replacements in Read Only Collecti…
Sewer56 7d2b40a
Fix: Use the latest database state when installing loadout items
Sewer56 898c9df
Improve: Be clear we're dealing with LibraryLinkedLoadoutItem(s) in L…
Sewer56 afcb68d
Fixed: XML Docs References
Sewer56 ce6d692
Updated: Use latest DB in LoadoutsWithLibraryItem
Sewer56 d7a0228
Improved: Description for InstallLoadoutItemJobResult
Sewer56 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,57 +1,31 @@ | ||
using Microsoft.Extensions.DependencyInjection; | ||
using NexusMods.Abstractions.Library; | ||
using NexusMods.Abstractions.Library.Models; | ||
using NexusMods.Abstractions.Loadouts; | ||
using NexusMods.App.UI.Overlays; | ||
using NexusMods.App.UI.Overlays.LibraryDeleteConfirmation; | ||
using NexusMods.MnemonicDB.Abstractions; | ||
using NexusMods.MnemonicDB.Abstractions.IndexSegments; | ||
using NexusMods.MnemonicDB.Abstractions.TxFunctions; | ||
namespace NexusMods.App.UI.Pages.Library; | ||
|
||
/// <summary> | ||
/// Utility helper class for removing a set of library items from inside a ViewModel. | ||
/// </summary> | ||
/// <remarks> | ||
/// This is here to help easier migration to new LoadoutItems based library UI | ||
/// when the time comes. | ||
/// This wraps the actual removal from loadouts and user facing UI confirmation | ||
/// into a single operation, so you can call this from anywhere and not have to | ||
/// worry too much about it. | ||
/// </remarks> | ||
public static class LibraryItemRemover | ||
{ | ||
public static async Task RemoveAsync( | ||
IConnection conn, | ||
IOverlayController overlayController, | ||
ILibraryService libraryService, | ||
LibraryItem.ReadOnly[] toRemove, | ||
CancellationToken cancellationToken = default) | ||
LibraryItem.ReadOnly[] toRemove) | ||
{ | ||
var warnings = LibraryItemDeleteWarningDetector.Process(conn, toRemove); | ||
var alphaWarningViewModel = LibraryItemDeleteConfirmationViewModel.FromWarningDetector(warnings); | ||
alphaWarningViewModel.Controller = overlayController; | ||
var result = await overlayController.EnqueueAndWait(alphaWarningViewModel); | ||
if (!result) return; | ||
|
||
if (result) | ||
{ | ||
// Note(sewer) Can the person reviewing this code let me know their opinion of | ||
// whether this should be inlined into LibraryService or not? | ||
var loadouts = Loadout.All(conn.Db).ToArray(); | ||
using var tx = conn.BeginTransaction(); | ||
|
||
// Note. A loadout may technically still be updated in the background via the CLI, | ||
// However this is unlikelu, and the possibility of a concurrent update | ||
// is always possible, as long as we show a blocking dialog to the user. | ||
foreach (var itemInLoadout in warnings.ItemsInLoadouts) | ||
{ | ||
foreach (var loadout in loadouts) | ||
{ | ||
foreach (var loadoutItem in loadout.GetLoadoutItemsByLibraryItem(itemInLoadout)) | ||
tx.Delete(loadoutItem, recursive: true); | ||
} | ||
} | ||
|
||
await tx.Commit(); | ||
await libraryService.RemoveItems(toRemove); | ||
} | ||
} | ||
} |
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
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need all of these methods?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The overloads with a tx allow you to do the operations as part of a larger transaction without committing.
The overloads without a create a transaction there and then, and do the changes on the spot.
RemoveLibraryItemsFromLoadout
I added because the code for that was duplicated in multiple places throughout the app; so I lifted it out and deduplicated.