Skip to content

Commit

Permalink
Improved aggregator character/person image sync logic
Browse files Browse the repository at this point in the history
  • Loading branch information
volbil committed Oct 15, 2024
1 parent 7ef1c17 commit 569efb3
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
15 changes: 11 additions & 4 deletions app/aggregator/characters.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def save_characters(session, data):
add_characters = []

for character_data in data:
new_image = False

if not (image := image_cache.get(character_data["image"])):
if character_data["image"]:
image = Image(
Expand All @@ -33,6 +35,7 @@ async def save_characters(session, data):
)

image_cache[character_data["image"]] = image
new_image = True

updated = utils.from_timestamp(character_data["updated"])
slug = utils.slugify(
Expand All @@ -42,10 +45,14 @@ async def save_characters(session, data):
if character_data["content_id"] in characters_cache:
character = characters_cache[character_data["content_id"]]

if character.updated == updated:
continue

if character.favorites == character_data["favorites"]:
# We only skip if there is nothing to update
if all(
[
character.updated == updated,
character.favorites == character_data["favorites"],
new_image is False,
]
):
continue

character.favorites = character_data["favorites"]
Expand Down
15 changes: 11 additions & 4 deletions app/aggregator/people.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ async def save_people(session, data):
add_people = []

for person_data in data:
new_image = False

if not (image := image_cache.get(person_data["image"])):
if person_data["image"]:
image = Image(
Expand All @@ -33,17 +35,22 @@ async def save_people(session, data):
)

image_cache[person_data["image"]] = image
new_image = True

updated = utils.from_timestamp(person_data["updated"])
slug = utils.slugify(person_data["name_en"], person_data["content_id"])

if person_data["content_id"] in people_cache:
person = people_cache[person_data["content_id"]]

if person.updated == updated:
continue

if person.favorites == person_data["favorites"]:
# We only skip if there is nothing to update
if all(
[
person.updated == updated,
person.favorites == person_data["favorites"],
new_image is False,
]
):
continue

person.favorites = person_data["favorites"]
Expand Down

0 comments on commit 569efb3

Please sign in to comment.