(core) Log number of rows in user tables in data engine

Summary:
Adds a method Table._num_rows using an empty lookup map column.

Adds a method Engine.count_rows which adds them all up.

Returns the count after applying user actions to be logged by ActiveDoc.

Test Plan: Added a unit test in Python. Tested log message manually.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3275
This commit is contained in:
Alex Hall
2022-02-21 16:19:11 +02:00
parent f1002c0e67
commit 437d30bd9f
13 changed files with 84 additions and 15 deletions

View File

@@ -225,6 +225,11 @@ class Table(object):
# which are 'flattened' so source records may appear in multiple groups
self._summary_simple = None
# For use in _num_rows. The attribute isn't strictly needed,
# but it makes _num_rows slightly faster, and only creating the lookup map when _num_rows
# is called seems to be too late, at least for unit tests.
self._empty_lookup_column = self._get_lookup_map(())
# Add Record and RecordSet subclasses which fill in this table as the first argument
class Record(records.Record):
def __init__(inner_self, *args, **kwargs): # pylint: disable=no-self-argument
@@ -237,6 +242,12 @@ class Table(object):
self.Record = Record
self.RecordSet = RecordSet
def _num_rows(self):
"""
Similar to `len(self.lookup_records())` but faster and doesn't create dependencies.
"""
return len(self._empty_lookup_column._do_fast_empty_lookup())
def _rebuild_model(self, user_table):
"""
Sets class-wide properties from a new Model class for the table (inner class within the table