Skip to content

Commit

Permalink
Make deleting and renaming inactive mods faster
Browse files Browse the repository at this point in the history
When mods are inactive, we don't have to commit when we delete them or
rename them. Skip this step in these cases, which should provide a
sizable speedup for these operations when used on large modlists.
  • Loading branch information
cyberrumor committed Mar 31, 2024
1 parent 78b32eb commit c48b51a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions ammo/mod_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,8 +700,9 @@ def rename(self, component: RenameEnum, index: int, name: str) -> None:
if new_location.exists():
raise Warning(f"A mod named {str(new_location)} already exists!")

# Remove symlinks instead of breaking them.
self._clean_game_dir()
if mod.enabled:
# Remove symlinks instead of breaking them.
self._clean_game_dir()

# Move the folder, update the mod.
mod.location.rename(new_location)
Expand All @@ -712,7 +713,8 @@ def rename(self, component: RenameEnum, index: int, name: str) -> None:
mod.__post_init__()

# re-install symlinks
self.commit()
if mod.enabled:
self.commit()

def delete(self, component: DeleteEnum, index: Union[int, str]) -> None:
"""
Expand Down Expand Up @@ -764,6 +766,8 @@ def delete(self, component: DeleteEnum, index: Union[int, str]) -> None:
if not mod.visible:
raise Warning("You can only delete visible components.")

originally_active = mod.enabled

# Remove the mod from the controller then delete it.
self._set_component_state(
ComponentEnum.MOD, self.mods.index(mod), False
Expand All @@ -773,7 +777,9 @@ def delete(self, component: DeleteEnum, index: Union[int, str]) -> None:
shutil.rmtree(mod.location)
except FileNotFoundError:
pass
self.commit()

if originally_active:
self.commit()

case DeleteEnum.PLUGIN:

Expand Down

0 comments on commit c48b51a

Please sign in to comment.