Page Menu
Home
Software Heritage
Search
Configure Global Search
Log In
Files
F7343094
D337.id1086.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
3 KB
Subscribers
None
D337.id1086.diff
View Options
diff --git a/swh/web/common/service.py b/swh/web/common/service.py
--- a/swh/web/common/service.py
+++ b/swh/web/common/service.py
@@ -297,15 +297,19 @@
directory information as dict.
"""
+ empty_dir_sha1 = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
+
+ if sha1_git == empty_dir_sha1:
+ return []
+
sha1_git_bin = _to_sha1_bin(sha1_git)
- dir = _first_element(storage.directory_get([sha1_git_bin]))
- if not dir:
+ directory_entries = storage.directory_ls(sha1_git_bin)
+ if directory_entries:
+ return map(converters.from_directory_entry, directory_entries)
+ else:
raise NotFoundExc('Directory with sha1_git %s not found' % sha1_git)
- directory_entries = storage.directory_ls(sha1_git_bin) or []
- return map(converters.from_directory_entry, directory_entries)
-
def lookup_directory_with_path(directory_sha1_git, path_string):
"""Return directory information for entry with path path_string w.r.t.
diff --git a/swh/web/tests/common/test_service.py b/swh/web/tests/common/test_service.py
--- a/swh/web/tests/common/test_service.py
+++ b/swh/web/tests/common/test_service.py
@@ -1702,19 +1702,19 @@
mock_query.parse_hash_with_algorithms_or_throws.return_value = (
'sha1',
'directory-id-bin')
- mock_storage.directory_get.return_value = None
+ mock_storage.directory_ls.return_value = []
# when
with self.assertRaises(NotFoundExc) as cm:
service.lookup_directory('directory_id')
- self.assertIn('Directory with sha1_git directory_id not found',
- cm.exception.args[0])
+
+ self.assertIn('Directory with sha1_git directory_id not found',
+ cm.exception.args[0])
# then
mock_query.parse_hash_with_algorithms_or_throws.assert_called_with(
'directory_id', ['sha1'], 'Only sha1_git is supported.')
- mock_storage.directory_get.assert_called_with(['directory-id-bin'])
- mock_storage.directory_ls.called = False
+ mock_storage.directory_ls.assert_called_with('directory-id-bin')
@patch('swh.web.common.service.storage')
@patch('swh.web.common.service.query')
@@ -1724,9 +1724,6 @@
'sha1',
'directory-sha1-bin')
- # something that exists is all that matters here
- mock_storage.directory_get.return_value = {'id': b'directory-sha1-bin'}
-
# given
stub_dir_entries = [{
'sha1': self.SHA1_SAMPLE_BIN,
@@ -1769,6 +1766,20 @@
@patch('swh.web.common.service.storage')
@istest
+ def lookup_directory_empty(self, mock_storage):
+ empty_dir_sha1 = '4b825dc642cb6eb9a060e54bf8d69288fbee4904'
+ mock_storage.directory_ls.return_value = []
+
+ # when
+ actual_directory_ls = list(service.lookup_directory(empty_dir_sha1))
+
+ # then
+ self.assertEqual(actual_directory_ls, [])
+
+ self.assertFalse(mock_storage.directory_ls.called)
+
+ @patch('swh.web.common.service.storage')
+ @istest
def lookup_revision_by_nothing_found(self, mock_storage):
# given
mock_storage.revision_get_by.return_value = None
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mar 17 2025, 7:19 PM (7 w, 3 d ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
3222407
Attached To
D337: Only hit the database once for directory listings
Event Timeline
Log In to Comment