Skip to content

Commit

Permalink
CompleteTheStash: Disable scene hooks by default to improve performance
Browse files Browse the repository at this point in the history
  • Loading branch information
MinasukiHikimuna committed Aug 30, 2024
1 parent ecf12f3 commit 1506032
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
16 changes: 11 additions & 5 deletions plugins/CompleteTheStash/CompleteTheStash.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class CompleteTheStashConfiguration:
sceneExcludeTags: str
stashDbSceneSource: MissingSceneSource
tpdbSceneSource: MissingSceneSource
enableSceneHooks: bool


def parse_url(url):
Expand Down Expand Up @@ -147,6 +148,7 @@ def get_complete_the_stash_config(local_configuration) -> CompleteTheStashConfig
sceneExcludeTags=scene_exclude_tags,
stashDbSceneSource=stash_db_configuration,
tpdbSceneSource=tpdb_configuration,
enableSceneHooks=complete_the_stash_config.get("enableSceneHooks", False),
)


Expand All @@ -166,6 +168,7 @@ def process_input(json_input, stash_completer: StashCompleter):
logger.debug(f"Processing input: {json_input}")
event_type = json_input.get("args", {}).get("hookContext", {}).get("type")
if json_input.get("args", {}).get("mode") == "process_performers":
logger.info(f"Processing performers for endpoint {stash_completer.stashbox_client.endpoint}.")
stash_completer.process_performers()
elif event_type in ["Scene.Create.Post", "Scene.Update.Post"]:
try:
Expand All @@ -179,7 +182,7 @@ def process_input(json_input, stash_completer: StashCompleter):
)
return

logger.debug(f"Processing scene create type {event_type} for scene {scene_id}.")
logger.debug(f"Processing scene create type {event_type} for scene {scene_id} for endpoint {stash_completer.stashbox_client.endpoint}.")
stash_completer.process_scene_by_id(scene_id)
else:
logger.error(f"Invalid input: {json_input}")
Expand Down Expand Up @@ -208,10 +211,13 @@ def execute():

complete_the_stash_config = get_complete_the_stash_config(local_configuration)

# Stop processing as soon as possible to improve performance if scene hooks are disabled.
event_type = json_input.get("args", {}).get("hookContext", {}).get("type")
if event_type in ["Scene.Create.Post", "Scene.Update.Post"] and not complete_the_stash_config.enableSceneHooks:
return

# StashDB
if complete_the_stash_config.stashDbSceneSource:
logger.info("Processing StashDB scenes.")

missing_stash_client = create_missing_stash_client(
complete_the_stash_config.stashDbSceneSource
)
Expand All @@ -231,6 +237,7 @@ def execute():
"performerTags": complete_the_stash_config.performerTags,
"stashboxEndpoint": complete_the_stash_config.stashDbSceneSource.stashboxEndpoint,
"sceneExcludeTags": complete_the_stash_config.sceneExcludeTags,
"enableSceneHooks": complete_the_stash_config.enableSceneHooks,
}
stash_completer = StashCompleter(
config,
Expand All @@ -243,8 +250,6 @@ def execute():

# TPDB
if complete_the_stash_config.tpdbSceneSource:
logger.info("Processing TPDB scenes.")

missing_stash_client = create_missing_stash_client(
complete_the_stash_config.tpdbSceneSource
)
Expand All @@ -264,6 +269,7 @@ def execute():
"performerTags": complete_the_stash_config.performerTags,
"stashboxEndpoint": complete_the_stash_config.tpdbSceneSource.stashboxEndpoint,
"sceneExcludeTags": complete_the_stash_config.sceneExcludeTags,
"enableSceneHooks": complete_the_stash_config.enableSceneHooks,
}
stash_completer = StashCompleter(
config,
Expand Down
7 changes: 6 additions & 1 deletion plugins/CompleteTheStash/CompleteTheStash.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: CompleteTheStash
description: Finds missing scenes for selected performers and creates missing scene metadata to another missing Stash instance. You can use either StashDB or TPDB or both as a source for missing scenes.
version: 0.4.6
version: 0.4.7
url: https://github.com/MinasukiHikimuna/MidnightRider-Stash/
exec:
- python
Expand Down Expand Up @@ -42,3 +42,8 @@ settings:
displayName: Exclude scenes with tags
description: Tags of the scenes to exclude from processing, e.g. Compilation. Separate multiple tags with commas.
type: STRING
enableSceneHooks:
displayName: Enable scene hooks
description: Enable the scene hooks. This will remove missing scenes from the missing Stash instances automatically when scenes are created or updated in the local Stash instance. Note that this will dramatically decrease performance as every scene update will trigger a hook which takes a couple of seconds.
type: BOOLEAN

0 comments on commit 1506032

Please sign in to comment.