From: ivan Date: Sun, 21 Dec 2003 23:13:41 +0000 (+0000) Subject: cache virtual_fields method results to help performance X-Git-Tag: NET_WHOIS_RAW_0_31~224 X-Git-Url: http://git.freeside.biz/gitweb/?p=freeside.git;a=commitdiff_plain;h=3dc9375300fa2b9706e2b5707694022962f65b4d;ds=sidebyside cache virtual_fields method results to help performance --- diff --git a/FS/FS/Record.pm b/FS/FS/Record.pm index 14dfca2cb..2517d1841 100644 --- a/FS/FS/Record.pm +++ b/FS/FS/Record.pm @@ -2,7 +2,7 @@ package FS::Record; use strict; use vars qw( $dbdef_file $dbdef $setup_hack $AUTOLOAD @ISA @EXPORT_OK $DEBUG - $me %dbdef_cache ); + $me %dbdef_cache %virtual_fields_cache ); use subs qw(reload_dbdef); use Exporter; use Carp qw(carp cluck croak confess); @@ -1379,14 +1379,17 @@ sub virtual_fields { return () unless $self->dbdef->table('part_virtual_field'); - # This should be smart enough to cache results. + unless ( $virtual_fields_cache{$table} ) { + my $query = 'SELECT name from part_virtual_field ' . + "WHERE dbtable = '$table'"; + my $dbh = dbh; + my $result = $dbh->selectcol_arrayref($query); + confess $dbh->errstr if $dbh->err; + $virtual_fields_cache{$table} = $result; + } + + @{$virtual_fields_cache{$table}}; - my $query = 'SELECT name from part_virtual_field ' . - "WHERE dbtable = '$table'"; - my $dbh = dbh; - my $result = $dbh->selectcol_arrayref($query); - confess $dbh->errstr if $dbh->err; - return @$result; }