arthexis 0.1.23__py3-none-any.whl → 0.1.25__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of arthexis might be problematic. Click here for more details.

nodes/utils.py CHANGED
@@ -90,10 +90,13 @@ def save_screenshot(
90
90
  *,
91
91
  content: str | None = None,
92
92
  user=None,
93
+ link_duplicates: bool = False,
93
94
  ):
94
95
  """Save screenshot file info if not already recorded.
95
96
 
96
- Returns the created :class:`ContentSample` or ``None`` if duplicate.
97
+ Returns the created :class:`ContentSample`. If ``link_duplicates`` is ``True``
98
+ and a sample with identical content already exists, the existing record is
99
+ returned instead of ``None``.
97
100
  """
98
101
 
99
102
  original = path
@@ -101,7 +104,11 @@ def save_screenshot(
101
104
  path = settings.LOG_DIR / path
102
105
  with path.open("rb") as fh:
103
106
  digest = hashlib.sha256(fh.read()).hexdigest()
104
- if ContentSample.objects.filter(hash=digest).exists():
107
+ existing = ContentSample.objects.filter(hash=digest).first()
108
+ if existing:
109
+ if link_duplicates:
110
+ logger.info("Duplicate screenshot content; reusing existing sample")
111
+ return existing
105
112
  logger.info("Duplicate screenshot content; record not created")
106
113
  return None
107
114
  stored_path = (original if not original.is_absolute() else path).as_posix()