Skip to content

Commit 58f2b67

Browse files
refactor: Remove unused functions from hash_registry
Remove dead code that was only tested but never used in production: - hash_exists (gc uses set operations on paths) - delete_hash (gc uses delete_path directly) - get_size (gc collects sizes during walk) - get_hash_size (wrapper for get_size) Remaining API: compute_hash, build_hash_path, get_store_backend, get_store_subfolding, put_hash, get_hash, delete_path Co-Authored-By: Claude Opus 4.5 <[email protected]>
1 parent d2ab4de commit 58f2b67

File tree

2 files changed

+0
-199
lines changed

2 files changed

+0
-199
lines changed

src/datajoint/hash_registry.py

Lines changed: 0 additions & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -267,34 +267,6 @@ def get_hash(metadata: dict[str, Any]) -> bytes:
267267
return data
268268

269269

270-
def hash_exists(
271-
content_hash: str,
272-
schema_name: str,
273-
store_name: str | None = None,
274-
) -> bool:
275-
"""
276-
Check if hash-addressed content exists in storage.
277-
278-
Parameters
279-
----------
280-
content_hash : str
281-
Base32-encoded hash (26 characters).
282-
schema_name : str
283-
Database/schema name for path isolation.
284-
store_name : str, optional
285-
Name of the store. If None, uses default store.
286-
287-
Returns
288-
-------
289-
bool
290-
True if content exists.
291-
"""
292-
subfolding = get_store_subfolding(store_name)
293-
path = build_hash_path(content_hash, schema_name, subfolding)
294-
backend = get_store_backend(store_name)
295-
return backend.exists(path)
296-
297-
298270
def delete_path(
299271
path: str,
300272
store_name: str | None = None,
@@ -328,88 +300,3 @@ def delete_path(
328300
logger.debug(f"Deleted: {path}")
329301
return True
330302
return False
331-
332-
333-
# Backward compatibility alias
334-
def delete_hash(
335-
content_hash: str,
336-
schema_name: str,
337-
store_name: str | None = None,
338-
) -> bool:
339-
"""
340-
Delete hash-addressed content from storage (deprecated).
341-
342-
.. deprecated::
343-
Use :func:`delete_path` with the stored path instead.
344-
345-
Parameters
346-
----------
347-
content_hash : str
348-
Base32-encoded hash (26 characters).
349-
schema_name : str
350-
Database/schema name for path isolation.
351-
store_name : str, optional
352-
Name of the store. If None, uses default store.
353-
354-
Returns
355-
-------
356-
bool
357-
True if content was deleted, False if it didn't exist.
358-
"""
359-
subfolding = get_store_subfolding(store_name)
360-
path = build_hash_path(content_hash, schema_name, subfolding)
361-
return delete_path(path, store_name)
362-
363-
364-
def get_size(
365-
path: str,
366-
store_name: str | None = None,
367-
) -> int:
368-
"""
369-
Get the size of content at the specified path.
370-
371-
Parameters
372-
----------
373-
path : str
374-
Storage path (as stored in metadata).
375-
store_name : str, optional
376-
Name of the store. If None, uses default store.
377-
378-
Returns
379-
-------
380-
int
381-
Size in bytes.
382-
"""
383-
backend = get_store_backend(store_name)
384-
return backend.size(path)
385-
386-
387-
# Backward compatibility alias
388-
def get_hash_size(
389-
content_hash: str,
390-
schema_name: str,
391-
store_name: str | None = None,
392-
) -> int:
393-
"""
394-
Get the size of hash-addressed content (deprecated).
395-
396-
.. deprecated::
397-
Use :func:`get_size` with the stored path instead.
398-
399-
Parameters
400-
----------
401-
content_hash : str
402-
Base32-encoded hash (26 characters).
403-
schema_name : str
404-
Database/schema name for path isolation.
405-
store_name : str, optional
406-
Name of the store. If None, uses default store.
407-
408-
Returns
409-
-------
410-
int
411-
Size in bytes.
412-
"""
413-
subfolding = get_store_subfolding(store_name)
414-
path = build_hash_path(content_hash, schema_name, subfolding)
415-
return get_size(path, store_name)

tests/integration/test_hash_storage.py

Lines changed: 0 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@
1010
from datajoint.hash_registry import (
1111
build_hash_path,
1212
compute_hash,
13-
hash_exists,
1413
delete_path,
15-
delete_hash,
1614
get_hash,
17-
get_size,
18-
get_hash_size,
1915
put_hash,
2016
)
2117
from datajoint.errors import DataJointError
@@ -192,34 +188,6 @@ def test_verifies_hash(self, mock_get_backend):
192188
get_hash(metadata)
193189

194190

195-
class TestHashExists:
196-
"""Tests for hash_exists function."""
197-
198-
@patch("datajoint.hash_registry.get_store_subfolding")
199-
@patch("datajoint.hash_registry.get_store_backend")
200-
def test_returns_true_when_exists(self, mock_get_backend, mock_get_subfolding):
201-
"""Test that True is returned when content exists."""
202-
mock_backend = MagicMock()
203-
mock_backend.exists.return_value = True
204-
mock_get_backend.return_value = mock_backend
205-
mock_get_subfolding.return_value = None
206-
207-
content_hash = "abcdefghijklmnopqrstuvwxyz"[:26] # Valid base32
208-
assert hash_exists(content_hash, schema_name="test_schema", store_name="test_store") is True
209-
210-
@patch("datajoint.hash_registry.get_store_subfolding")
211-
@patch("datajoint.hash_registry.get_store_backend")
212-
def test_returns_false_when_not_exists(self, mock_get_backend, mock_get_subfolding):
213-
"""Test that False is returned when content doesn't exist."""
214-
mock_backend = MagicMock()
215-
mock_backend.exists.return_value = False
216-
mock_get_backend.return_value = mock_backend
217-
mock_get_subfolding.return_value = None
218-
219-
content_hash = "abcdefghijklmnopqrstuvwxyz"[:26] # Valid base32
220-
assert hash_exists(content_hash, schema_name="test_schema", store_name="test_store") is False
221-
222-
223191
class TestDeletePath:
224192
"""Tests for delete_path function."""
225193

@@ -248,57 +216,3 @@ def test_returns_false_for_nonexistent(self, mock_get_backend):
248216

249217
assert result is False
250218
mock_backend.remove.assert_not_called()
251-
252-
253-
class TestDeleteHash:
254-
"""Tests for delete_hash function (backward compatibility)."""
255-
256-
@patch("datajoint.hash_registry.get_store_subfolding")
257-
@patch("datajoint.hash_registry.get_store_backend")
258-
def test_deletes_existing_content(self, mock_get_backend, mock_get_subfolding):
259-
"""Test deleting existing content by hash."""
260-
mock_backend = MagicMock()
261-
mock_backend.exists.return_value = True
262-
mock_get_backend.return_value = mock_backend
263-
mock_get_subfolding.return_value = None
264-
265-
content_hash = "abcdefghijklmnopqrstuvwxyz"[:26] # Valid base32
266-
result = delete_hash(content_hash, schema_name="test_schema", store_name="test_store")
267-
268-
assert result is True
269-
mock_backend.remove.assert_called_once()
270-
271-
272-
class TestGetSize:
273-
"""Tests for get_size function."""
274-
275-
@patch("datajoint.hash_registry.get_store_backend")
276-
def test_returns_size(self, mock_get_backend):
277-
"""Test getting content size by path."""
278-
mock_backend = MagicMock()
279-
mock_backend.size.return_value = 1024
280-
mock_get_backend.return_value = mock_backend
281-
282-
path = "_hash/test_schema/abcdefghijklmnopqrst"
283-
result = get_size(path, store_name="test_store")
284-
285-
assert result == 1024
286-
mock_backend.size.assert_called_once_with(path)
287-
288-
289-
class TestGetHashSize:
290-
"""Tests for get_hash_size function (backward compatibility)."""
291-
292-
@patch("datajoint.hash_registry.get_store_subfolding")
293-
@patch("datajoint.hash_registry.get_store_backend")
294-
def test_returns_size(self, mock_get_backend, mock_get_subfolding):
295-
"""Test getting content size by hash."""
296-
mock_backend = MagicMock()
297-
mock_backend.size.return_value = 1024
298-
mock_get_backend.return_value = mock_backend
299-
mock_get_subfolding.return_value = None
300-
301-
content_hash = "abcdefghijklmnopqrstuvwxyz"[:26] # Valid base32
302-
result = get_hash_size(content_hash, schema_name="test_schema", store_name="test_store")
303-
304-
assert result == 1024

0 commit comments

Comments
 (0)