From 3274cbad045d9ee2e67384564d772a019cad0c9e Mon Sep 17 00:00:00 2001 From: Ned Batchelder Date: Sun, 11 Oct 2020 11:12:04 -0400 Subject: Fix --source performance regression. #1037 --- coverage/sqldata.py | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'coverage/sqldata.py') diff --git a/coverage/sqldata.py b/coverage/sqldata.py index b8ee8853..702bd42b 100644 --- a/coverage/sqldata.py +++ b/coverage/sqldata.py @@ -167,7 +167,8 @@ class CoverageData(SimpleReprMixin): To record data for contexts, use :meth:`set_context` to set a context to be used for subsequent :meth:`add_lines` and :meth:`add_arcs` calls. - To add a source file without any measured data, use :meth:`touch_file`. + To add a source file without any measured data, use :meth:`touch_file`, + or :meth:`touch_files` for a list of such files. Write the data to its file with :meth:`write`. @@ -536,16 +537,26 @@ class CoverageData(SimpleReprMixin): `plugin_name` is the name of the plugin responsible for this file. It is used to associate the right filereporter, etc. """ + self.touch_files([filename], plugin_name) + + def touch_files(self, filenames, plugin_name=""): + """Ensure that `filenames` appear in the data, empty if needed. + + `plugin_name` is the name of the plugin responsible for these files. It is used + to associate the right filereporter, etc. + """ if self._debug.should('dataop'): - self._debug.write("Touching %r" % (filename,)) + self._debug.write("Touching %r" % (filenames,)) self._start_using() - if not self._has_arcs and not self._has_lines: - raise CoverageException("Can't touch files in an empty CoverageData") - - self._file_id(filename, add=True) - if plugin_name: - # Set the tracer for this file - self.add_file_tracers({filename: plugin_name}) + with self._connect(): # Use this to get one transaction. + if not self._has_arcs and not self._has_lines: + raise CoverageException("Can't touch files in an empty CoverageData") + + for filename in filenames: + self._file_id(filename, add=True) + if plugin_name: + # Set the tracer for this file + self.add_file_tracers({filename: plugin_name}) def update(self, other_data, aliases=None): """Update this data with data from several other :class:`CoverageData` instances. -- cgit v1.2.1