Changeset 1733


Ignore:
Timestamp:
03/04/16 10:28:11 (8 years ago)
Author:
nanardon
Message:

Cache objects existance

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/LATMOS-Accounts/lib/LATMOS/Accounts/Bases/Sql/objects.pm

    r1694 r1733  
    178178sub new { 
    179179    my ($class, $base, $id) = @_; 
    180     my $sth = $base->db->prepare_cached( 
    181         sprintf(q{select 1 from %s where %s = ? %s}, 
    182             $base->db->quote_identifier($class->_object_table), 
    183             $base->db->quote_identifier($class->_key_field), 
    184             ($base->{wexported} ? '' : 'and exported = true'), 
    185         ), 
    186     ); 
    187     my $count = $sth->execute($id); 
    188     $sth->finish; 
    189     ($count || 0) == 1 or return; 
     180 
     181    my $__cache = $base->{__cache}{"_" . $class->type}; 
     182 
     183    if (!(exists($__cache->{$id}) 
     184        && $__cache->{$id}{__time} >= time - 1)) { 
     185 
     186        my $sth = $base->db->prepare_cached( 
     187            sprintf(q{select 1 from %s where %s = ? %s}, 
     188                $base->db->quote_identifier($class->_object_table), 
     189                $base->db->quote_identifier($class->_key_field), 
     190                ($base->{wexported} ? '' : 'and exported = true'), 
     191            ), 
     192        ); 
     193        my $count = $sth->execute($id); 
     194        $sth->finish; 
     195        ($count || 0) == 1 or return; 
     196    } 
    190197    $class->SUPER::new($base, $id); 
    191198} 
     
    284291    my ($class, $base, $id) = @_; 
    285292 
     293    my $__cache = $base->{__cache}{"_" . $class->type}; 
     294 
    286295    my $obj = $base->get_object($class->type, $id) 
    287296        or return; 
     
    294303        ) 
    295304    ); 
    296     $sthd->execute($id); 
     305    my $res = $sthd->execute($id); 
     306    if ($res) { 
     307        delete($__cache->{$id}); 
     308    } 
     309 
     310    $res 
    297311} 
    298312 
Note: See TracChangeset for help on using the changeset viewer.