1010def processAll ():
1111 exclusion_marker_tag_id = None
1212 if settings ["excludeSceneWithTag" ] != "" :
13- exclussion_marker_tag = stash .find_tag (settings ["excludeSceneWithTag" ])
14- if exclussion_marker_tag is not None :
15- exclusion_marker_tag_id = exclussion_marker_tag ['id' ]
13+ exclusion_marker_tag = stash .find_tag (settings ["excludeSceneWithTag" ])
14+ if exclusion_marker_tag is not None :
15+ exclusion_marker_tag_id = exclusion_marker_tag ['id' ]
1616
1717 query = {
1818 "tags" : {
@@ -32,9 +32,8 @@ def processAll():
3232 processed = 0
3333 page = 0
3434
35- while True :
36- if performersTotal > 0 :
37- log .progress (min (processed / performersTotal , 1.0 ))
35+ while performersTotal > processed :
36+ log .progress (min (processed / performersTotal , 1.0 ))
3837
3938 performers = stash .find_performers (
4039 f = query ,
@@ -43,26 +42,25 @@ def processAll():
4342 )
4443
4544 if not performers :
46- log .info ("Finished processing all performers." )
4745 break
4846
4947 for perf in performers :
50- performer_tags_ids = []
51- performer_tags_names = []
52- for performer_tag in perf .get ("tags" ,[]):
53- if settings ["excludeTagWithIgnoreAutoTag" ] and performer_tag ["ignore_auto_tag" ]:
54- continue
55- performer_tags_ids .append (performer_tag ["id" ])
56- performer_tags_names .append (performer_tag ["name" ])
57-
58- if not performer_tags_ids :
48+ perf_tags = perf .get ("tags" , [])
49+ if not perf_tags :
5950 processed += 1
6051 continue
6152
53+ performer_tags_ids = set ()
54+ performer_tags_names = set ()
55+
56+ for tag in perf ["tags" ]:
57+ performer_tags_ids .add (tag ["id" ])
58+ performer_tags_names .add (tag ["name" ])
59+
6260 scene_query = {
6361 "performers" : {
6462 "value" : [perf ["id" ]],
65- "modifier" : "INCLUDES_ALL "
63+ "modifier" : "INCLUDES "
6664 }
6765 }
6866 if settings ['excludeSceneOrganized' ]:
@@ -89,35 +87,51 @@ def processAll():
8987 stash .update_scenes (
9088 {
9189 "ids" : batch ,
92- "tag_ids" : {"mode" : "ADD" , "ids" : performer_tags_ids },
90+ "tag_ids" : {"mode" : "ADD" , "ids" : list ( performer_tags_ids ) },
9391 }
9492 )
9593 processed += 1
9694 page += 1
9795
96+ log .info ("Finished processing all performers." )
97+
9898
9999def processScene (scene : dict ):
100+ # Skip if organized
101+ if settings ['excludeSceneOrganized' ] and scene .get ('organized' ):
102+ log .debug ("Skipping scene update because it is organized" )
103+ return
104+
105+ # Skip if tagged with the excluded tag
106+ scene_tags = scene .get ("tags" , [])
100107 if settings ["excludeSceneWithTag" ] != "" :
101- for tag in scene . get ( "tags" , []) :
108+ for tag in scene_tags :
102109 if tag ["name" ] == settings ["excludeSceneWithTag" ]:
110+ log .debug ("Skipping scene because it has the excluded tag" )
103111 return
104112
105- if settings ['excludeSceneOrganized' ] and scene .get ('organized' ):
113+ perf_tag_ids = set ()
114+ for perf in scene .get ("performers" , []):
115+ perf_tag_ids .update (map (lambda tag : tag ["id" ], perf .get ("tags" , [])))
116+
117+ # Skip if no performer tags
118+ if not perf_tag_ids :
119+ log .debug ("Skipping scene update because performers have no tags" )
106120 return
107121
108- target_tag_ids = []
109- for perf in scene .get ("performers" , []):
110- for tag in perf .get ("tags" , []):
111- if settings ["excludeTagWithIgnoreAutoTag" ] and tag ["ignore_auto_tag" ]:
112- continue
113- target_tag_ids .append (tag ["id" ])
122+ scene_tag_ids = set (map (lambda tag : tag ["id" ], scene_tags ))
114123
115- if not target_tag_ids :
124+ # Skip if scene already has all performer tags
125+ if perf_tag_ids .issubset (scene_tag_ids ):
126+ log .debug ("Skipping scene update because it already has all performer tags" )
116127 return
117128
118- stash .update_scenes ({
119- "ids" : [scene ["id" ]],
120- "tag_ids" : {"mode" : "ADD" , "ids" : list (set (target_tag_ids ))}
129+ log .debug (f"Updating scene { scene ['id' ]} with performer tags: { perf_tag_ids } " )
130+ scene_tag_ids .update (perf_tag_ids )
131+
132+ stash .update_scene ({
133+ "id" : scene ["id" ],
134+ "tag_ids" : list (scene_tag_ids )
121135 })
122136
123137
@@ -147,6 +161,6 @@ def processScene(scene: dict):
147161 and len (json_input ["args" ]["hookContext" ]["inputFields" ]) > 1
148162 ):
149163 # Enforce explicit studio object allocation inside our graphQL post-hook criteria
150- scene = stash .find_scene (id , fragment = "id organized tags { name } performers { id tags { id ignore_auto_tag } } studio { id }" )
164+ scene = stash .find_scene (id , fragment = "id organized tags { id name } performers { id tags { id } }" )
151165 if scene :
152166 processScene (scene )
0 commit comments