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
master
Felix Stupp 2 years ago
parent 748201ec2b
commit 1145a09e3e
Signed by: zocker
GPG Key ID: 93E1BD26F6B02FB7

@ -5,6 +5,7 @@ import base64
import dataclasses import dataclasses
from dataclasses import dataclass from dataclasses import dataclass
from datetime import datetime from datetime import datetime
from functools import cache
import gzip import gzip
import json import json
import math import math
@ -395,15 +396,15 @@ def generate_preference_list(
limit: Optional[int] = None, limit: Optional[int] = None,
) -> List[MediaElement]: ) -> List[MediaElement]:
res_ids = list[int]() res_ids = list[int]()
tag_map = dict[MediaCollection, Tag]()
element_list = object_gen() element_list = object_gen()
for element in element_list: collections: Iterable[MediaCollection] = MediaCollection.select()
for link in element.collection_links: for coll in collections:
if link.collection not in tag_map: coll.tag_list.add(
tag = Tag(title="Automatic") Tag(
tag.use_for_preferences = True title="Automatic",
link.collection.tag_list.add(tag) use_for_preferences=True,
tag_map[link.collection] = tag )
)
orm.flush() orm.flush()
while True: while True:
if len(element_list) <= 0: if len(element_list) <= 0:

Loading…
Cancel
Save