@@ -68,7 +68,11 @@ def create_or_update_sneaker(
6868 link .platform : link .url for link in existing_sneaker .links
6969 }
7070 for new_link in sneaker .links :
71- if existing_links .get (new_link .platform ) != new_link .url :
71+ if existing_links .get (new_link .platform ) == new_link .url :
72+ # Skip if we already have this exact link
73+ continue
74+ elif new_link .platform in existing_links :
75+ # Log warning if we're trying to add a different URL for the same platform
7276 logfire .warning (
7377 f"{ sneaker .brand } SKU '{ sneaker .sku } ' already has a link for { new_link .platform } " ,
7478 sneaker_id = existing_sneaker .id ,
@@ -78,20 +82,47 @@ def create_or_update_sneaker(
7882 new_link = new_link .url ,
7983 )
8084 else :
85+ # Only add if we don't have a link for this platform yet
8186 new_link .sneaker = existing_sneaker
8287 existing_sneaker .links .append (new_link )
8388
8489 # Add any new images
85- existing_image_urls = {image .url for image in existing_sneaker .images }
90+ existing_images = {
91+ (image .platform , image .position ): image .url
92+ for image in existing_sneaker .images
93+ }
8694 for image in sneaker .images :
87- if image .url not in existing_image_urls :
95+ key = (image .platform , image .position )
96+ if existing_images .get (key ) == image .url :
97+ # Skip if we already have this exact image
98+ continue
99+ elif key in existing_images :
100+ # Log warning if we're trying to add a different URL for the same platform/position
101+ logfire .warning (
102+ f"{ sneaker .brand } SKU '{ sneaker .sku } ' already has an image for { image .platform } at position { image .position } " ,
103+ sneaker_id = existing_sneaker .id ,
104+ sneaker_sku = sneaker .sku ,
105+ sneaker_brand = sneaker .brand ,
106+ existing_image = existing_images [key ],
107+ new_image = image .url ,
108+ )
109+ else :
110+ # Only add if we don't have an image for this platform/position yet
88111 image .sneaker = existing_sneaker
89112 existing_sneaker .images .append (image )
90113
91114 # Add any new sizes
92- existing_size_values = {size .value for size in existing_sneaker .sizes }
115+ existing_sizes = {
116+ (size .value , size .size_standard ): size
117+ for size in existing_sneaker .sizes
118+ }
93119 for size in sneaker .sizes :
94- if size .value not in existing_size_values :
120+ key = (size .value , size .size_standard )
121+ if key in existing_sizes :
122+ # Skip if we already have this size
123+ continue
124+ else :
125+ # Only add if we don't have this size yet
95126 size .sneaker = existing_sneaker
96127 existing_sneaker .sizes .append (size )
97128
0 commit comments