Add map_function to get_history. (#9056)

This commit is contained in:
comfyanonymous 2025-07-25 18:25:45 -07:00 committed by GitHub
parent c60467a148
commit b850d9a8bb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1097,7 +1097,7 @@ class PromptQueue:
return True return True
return False return False
def get_history(self, prompt_id=None, max_items=None, offset=-1): def get_history(self, prompt_id=None, max_items=None, offset=-1, map_function=None):
with self.mutex: with self.mutex:
if prompt_id is None: if prompt_id is None:
out = {} out = {}
@ -1106,13 +1106,21 @@ class PromptQueue:
offset = len(self.history) - max_items offset = len(self.history) - max_items
for k in self.history: for k in self.history:
if i >= offset: if i >= offset:
out[k] = self.history[k] p = self.history[k]
if map_function is not None:
p = map_function(p)
out[k] = p
if max_items is not None and len(out) >= max_items: if max_items is not None and len(out) >= max_items:
break break
i += 1 i += 1
return out return out
elif prompt_id in self.history: elif prompt_id in self.history:
return {prompt_id: copy.deepcopy(self.history[prompt_id])} p = self.history[prompt_id]
if map_function is None:
p = copy.deepcopy(p)
else:
p = map_function(p)
return {prompt_id: p}
else: else:
return {} return {}