mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
(core) Compute sample_record lazily using a property
Summary: This changes Table.sample_record from a regular attribute to a property that's only computed when it's needed, which is only for autocompletion. This means it's not cached any more, but it's also not recomputed every time the schema changes. Profiling showed that _make_sample_record took a signification portion of time, and this change makes the tests 2 or 3 seconds faster. Test Plan: existing tests Reviewers: paulfitz Reviewed By: paulfitz Subscribers: paulfitz Differential Revision: https://phab.getgrist.com/D3334
This commit is contained in:
parent
59436d2bca
commit
4ce492b9e5
@ -248,6 +248,16 @@ class Table(object):
|
||||
"""
|
||||
return len(self._empty_lookup_column._do_fast_empty_lookup())
|
||||
|
||||
@property
|
||||
def sample_record(self):
|
||||
"""
|
||||
Used for auto-completion as a record with correct properties of correct types.
|
||||
"""
|
||||
return _make_sample_record(
|
||||
self.table_id,
|
||||
[col for col_id, col in self.all_columns.items() if col_id not in self._special_cols],
|
||||
)
|
||||
|
||||
def _rebuild_model(self, user_table):
|
||||
"""
|
||||
Sets class-wide properties from a new Model class for the table (inner class within the table
|
||||
@ -267,9 +277,6 @@ class Table(object):
|
||||
default_func = self.Model.__dict__.get(get_default_func_name(col_id))
|
||||
new_cols[col_id] = self._create_or_update_col(col_id, col_model, default_func)
|
||||
|
||||
# Used for auto-completion as a record with correct properties of correct types.
|
||||
self.sample_record = _make_sample_record(self.table_id, six.itervalues(new_cols))
|
||||
|
||||
# Note that we reuse previous special columns like lookup maps, since those not affected by
|
||||
# column changes should stay the same. These get removed when unneeded using other means.
|
||||
new_cols.update(sorted(six.iteritems(self._special_cols)))
|
||||
|
Loading…
Reference in New Issue
Block a user