From ab70c74a04a01e6afafb44ebbb1df76a269e2ca2 Mon Sep 17 00:00:00 2001 From: Andrew Nicols Date: Wed, 27 Mar 2024 11:49:06 +0800 Subject: [PATCH] MDL-81327 core: Remove unnecessary table filter The \Traversable interface does not define the `valid` method. Furthermore, the `valid` method actually checks that there is a _next_ value, which requires the value already be fetched and waiting. This is not the case for all Iterators. For example the CallbackFilterIterator does not load the initial value until it is requested. It is completely unnecessary to do this check anyway as an invalid Iterator will just not return any values. --- lib/tablelib.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/tablelib.php b/lib/tablelib.php index fcbab0ad5f4..0ecacd6e2f8 100644 --- a/lib/tablelib.php +++ b/lib/tablelib.php @@ -2064,6 +2064,8 @@ class table_sql extends flexible_table { } /** + * Build the table from the fetched data. + * * Take the data returned from the db_query and go through all the rows * processing each col using either col_{columnname} method or other_cols * method or if other_cols returns NULL then put the data straight into the @@ -2072,18 +2074,13 @@ class table_sql extends flexible_table { * After calling this function, don't forget to call close_recordset. */ public function build_table() { - - if ($this->rawdata instanceof \Traversable && !$this->rawdata->valid()) { - return; - } if (!$this->rawdata) { return; } foreach ($this->rawdata as $row) { $formattedrow = $this->format_row($row); - $this->add_data_keyed($formattedrow, - $this->get_row_class($row)); + $this->add_data_keyed($formattedrow, $this->get_row_class($row)); } }