From 98bcd4aad0bfef2c7bf3c91811a34a511d072504 Mon Sep 17 00:00:00 2001 From: Matthew Bucci Date: Tue, 16 Jan 2024 21:49:06 -0800 Subject: [PATCH] improve performance of sequence lookup --- pg4wp/driver_pgsql.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pg4wp/driver_pgsql.php b/pg4wp/driver_pgsql.php index 06c99d5..cea215a 100644 --- a/pg4wp/driver_pgsql.php +++ b/pg4wp/driver_pgsql.php @@ -1059,9 +1059,20 @@ function wpsqli_get_list_of_sequences(&$connection) // Get the primary sequence for a table function wpsqli_get_primary_sequence_for_table(&$connection, $table) { + // TODO: it should be possible to use a WP transient here for object caching + global $sequence_lookup; + if (empty($sequence_lookup)) { + $sequence_lookup = []; + } + + if (isset($sequence_lookup[$table])) { + return $sequence_lookup[$table]; + } + $sequences = wpsqli_get_list_of_sequences($connection); foreach($sequences as $sequence) { if (strncmp($sequence, $table, strlen($table)) === 0) { + $sequence_lookup[$table] = $sequence; return $sequence; } }