From 2d07cf35cecb0813593c8aa8023c0bd56ce72fde Mon Sep 17 00:00:00 2001
From: manonBlanco <blanco@teklia.com>
Date: Tue, 12 Sep 2023 16:26:41 +0200
Subject: [PATCH] Do not compute ratio

---
 arkindex_worker/cache.py  | 11 +----------
 arkindex_worker/models.py |  9 +--------
 tests/test_cache.py       |  4 ++--
 tests/test_element.py     |  6 +++---
 4 files changed, 7 insertions(+), 23 deletions(-)

diff --git a/arkindex_worker/cache.py b/arkindex_worker/cache.py
index 0d4ad784..233c7d93 100644
--- a/arkindex_worker/cache.py
+++ b/arkindex_worker/cache.py
@@ -157,17 +157,8 @@ class CachedElement(Model):
                 max_height is None or self.image.height <= max_height
             ):
                 resize = "full"
-            elif max_width is not None and max_height is not None:
-                resize = f"{max_width},{max_height}"
             else:
-                ratio = max(
-                    (max_width or 0) / self.image.width,
-                    (max_height or 0) / self.image.height,
-                )
-                new_width, new_height = int(self.image.width * ratio), int(
-                    self.image.height * ratio
-                )
-                resize = f"{new_width},{new_height}"
+                resize = f"{max_width or ''},{max_height or ''}"
 
         url = self.image.url
         if not url.endswith("/"):
diff --git a/arkindex_worker/models.py b/arkindex_worker/models.py
index 94df7bcc..d79495a6 100644
--- a/arkindex_worker/models.py
+++ b/arkindex_worker/models.py
@@ -205,15 +205,8 @@ class Element(MagicDict):
             ):
                 resize = "full"
             # Resizing if the image is bigger than the wanted size.
-            elif max_width is not None and max_height is not None:
-                resize = f"{max_width},{max_height}"
             else:
-                ratio = max(
-                    (max_width or 0) / original_size["w"],
-                    (max_height or 0) / original_size["h"],
-                )
-                new_width, new_height = [int(x * ratio) for x in original_size.values()]
-                resize = "{},{}".format(new_width, new_height)
+                resize = f"{max_width or ''},{max_height or ''}"
 
         if use_full_image:
             url = self.image_url(resize)
diff --git a/tests/test_cache.py b/tests/test_cache.py
index 78438aaa..53430b30 100644
--- a/tests/test_cache.py
+++ b/tests/test_cache.py
@@ -240,7 +240,7 @@ def test_check_version_same_version(tmp_path):
             600,
             None,
             400,
-            "http://something/full/266,400/0/default.jpg",
+            "http://something/full/,400/0/default.jpg",
         ),
         (
             600,
@@ -251,7 +251,7 @@ def test_check_version_same_version(tmp_path):
             400,
             400,
             None,
-            "http://something/full/400,266/0/default.jpg",
+            "http://something/full/400,/0/default.jpg",
         ),
         (
             400,
diff --git a/tests/test_element.py b/tests/test_element.py
index 09d45c86..734d5c81 100644
--- a/tests/test_element.py
+++ b/tests/test_element.py
@@ -105,7 +105,7 @@ def test_open_image_resize_portrait(mocker):
     assert elt.open_image(max_height=400, use_full_image=True) == "an image!"
     assert open_mock.call_count == 2
     assert open_mock.call_args == mocker.call(
-        "http://something/full/266,400/0/default.jpg",
+        "http://something/full/,400/0/default.jpg",
         rotation_angle=0,
         mirrored=False,
     )
@@ -178,7 +178,7 @@ def test_open_image_resize_landscape(mocker):
     assert elt.open_image(max_width=400, use_full_image=True) == "an image!"
     assert open_mock.call_count == 2
     assert open_mock.call_args == mocker.call(
-        "http://something/full/400,266/0/default.jpg",
+        "http://something/full/400,/0/default.jpg",
         rotation_angle=0,
         mirrored=False,
     )
@@ -388,7 +388,7 @@ def test_open_image_resize_use_full_image_false(mocker):
     assert elt.open_image(max_height=200, use_full_image=False) == "an image!"
     assert open_mock.call_count == 1
     assert open_mock.call_args == mocker.call(
-        "http://zoneurl/0,0,400,600/133,200/0/default.jpg",
+        "http://zoneurl/0,0,400,600/,200/0/default.jpg",
         rotation_angle=0,
         mirrored=False,
     )
-- 
GitLab