File tree Expand file tree Collapse file tree
src/solesearch_api/tasks/db Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import logfire
22from sqlmodel import Session , select
33
4+ from solesearch_api .models .enums import Platform
45from solesearch_api .models .sneaker import Sneaker
56from solesearch_api .db import engine
67
@@ -63,9 +64,20 @@ def create_or_update_sneaker(
6364 )
6465
6566 # Add any new links
66- existing_link_urls = {link .url for link in existing_sneaker .links }
67- for link in sneaker .links :
68- if link .url not in existing_link_urls :
67+ existing_links = {
68+ link .platform : link .url for link in existing_sneaker .links
69+ }
70+ for platform , link in sneaker .links .items ():
71+ if existing_links .get (platform ) == link .url :
72+ logfire .warning (
73+ f"{ sneaker .brand } SKU '{ sneaker .sku } ' already has a link for { platform } " ,
74+ sneaker_id = existing_sneaker .id ,
75+ sneaker_sku = sneaker .sku ,
76+ sneaker_brand = sneaker .brand ,
77+ existing_link = existing_links [platform ],
78+ new_link = link .url ,
79+ )
80+ else :
6981 link .sneaker = existing_sneaker
7082 existing_sneaker .links .append (link )
7183
You can’t perform that action at this time.
0 commit comments