Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/aiida/orm/implementation/storage_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,22 @@ def get_orm_entities(self, detailed: bool = False) -> dict:
count = QueryBuilder(self).append(Node).count()
data['Nodes'] = {'count': count}
if detailed:
first_time = (
QueryBuilder(self)
.append(Node, project=['ctime'], tag='node')
.order_by({'node': {'ctime': 'asc'}})
.first(flat=True)
)
last_time = (
QueryBuilder(self)
.append(Node, project=['ctime'], tag='node')
.order_by({'node': {'ctime': 'desc'}})
.first(flat=True)
)

data['Nodes']['first_created'] = str(first_time) if first_time else None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing None if there are no Nodes results in the following output from verdi storage info --detailed

  Nodes:
    count: 0
    first_created: null
    last_created: null
    node_types: []
    process_types: []

an alternative would be to pass en empty string, which would then look like this:

  Nodes:
    count: 0
    first_created: ''
    last_created: ''
    node_types: []
    process_types: []

I think None makes sense here. cc @GeigerJ2

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, agreed, I think null is fine :3
As always, thanks for the review, @danielhollas 🫶

data['Nodes']['last_created'] = str(last_time) if last_time else None

node_types = sorted(
{typ for (typ,) in QueryBuilder(self).append(Node, project=['node_type']).iterall() if typ is not None}
)
Expand Down
17 changes: 15 additions & 2 deletions tests/storage/psql_dos/test_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ def mock_maintain(self, live=True, dry_run=False, compress=False, **kwargs):

def test_get_info(monkeypatch):
"""Test the ``get_info`` method."""
from aiida import orm

storage_backend = get_manager().get_profile_storage()

def mock_get_info(self, detailed=False, **kwargs):
Expand All @@ -128,13 +130,24 @@ def mock_get_info(self, detailed=False, **kwargs):
assert 'extra_value' not in repository_info_out
assert repository_info_out['value'] == 42

storage_info_out = storage_backend.get_info(detailed=True)
repository_info_out = storage_info_out['repository']
node1 = orm.Data().store()
node2 = orm.Data().store()

detailed_storage_info_out = storage_backend.get_info(detailed=True)
repository_info_out = detailed_storage_info_out['repository']
assert 'value' in repository_info_out
assert 'extra_value' in repository_info_out
assert repository_info_out['value'] == 42
assert repository_info_out['extra_value'] == 0

# Test first_created and last_created timestamps
nodes_info = detailed_storage_info_out['entities']['Nodes']

assert 'first_created' in nodes_info
assert 'last_created' in nodes_info
assert nodes_info['first_created'] == str(node1.ctime)
assert nodes_info['last_created'] == str(node2.ctime)


def test_unload_profile():
"""Test that unloading the profile closes all sqla sessions.
Expand Down