From 1145a09e3e77bebf22cb3ca726e5bc43d3e91d20 Mon Sep 17 00:00:00 2001 From: Felix Stupp Date: Sat, 5 Nov 2022 22:47:48 +0100 Subject: [PATCH] generate_preference_list: Add "collection tags" by iter collections itering collections than elements for their collections is most of the time faster as mostly all collections are involved --- server/entertainment_decider/models.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/server/entertainment_decider/models.py b/server/entertainment_decider/models.py index 93ab86e..8afe0d0 100644 --- a/server/entertainment_decider/models.py +++ b/server/entertainment_decider/models.py @@ -5,6 +5,7 @@ import base64 import dataclasses from dataclasses import dataclass from datetime import datetime +from functools import cache import gzip import json import math @@ -395,15 +396,15 @@ def generate_preference_list( limit: Optional[int] = None, ) -> List[MediaElement]: res_ids = list[int]() - tag_map = dict[MediaCollection, Tag]() element_list = object_gen() - for element in element_list: - for link in element.collection_links: - if link.collection not in tag_map: - tag = Tag(title="Automatic") - tag.use_for_preferences = True - link.collection.tag_list.add(tag) - tag_map[link.collection] = tag + collections: Iterable[MediaCollection] = MediaCollection.select() + for coll in collections: + coll.tag_list.add( + Tag( + title="Automatic", + use_for_preferences=True, + ) + ) orm.flush() while True: if len(element_list) <= 0: