14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
17
# $Id: DB.pm,v 1.9 2008/11/23 20:52:00 ssinyagin Exp $
18
18
# Stanislav Sinyagin <ssinyagin@yahoo.com>
20
20
package Torrus::DB;
570
590
# Comma-separated list manipulation
592
sub _populateListCache
597
if( not exists( $self->{'listcache'}{$key} ) )
600
my $values = $self->get($key);
601
if( defined( $values ) )
603
foreach my $val (split(/,/o, $values))
608
$self->{'listcache'}{$key} = $ref;
618
if( not $self->{'delay_list_commit'} )
620
$self->put($key, join(',', keys %{$self->{'listcache'}{$key}}));
574
627
my $self = shift;
577
my $must_unique = shift;
581
if( exists( $self->{'listcache'}{$key} ) )
583
$list = $self->{'listcache'}{$key};
587
$list = $self->get($key);
588
$self->{'listcache'}{$key} = $list;
591
if( defined($list) and length($list) > 0 )
594
if( grep {$newname eq $_} split(',', $list) )
596
# This name is already in the list
597
return $must_unique ? 0:1;
604
$list .= $prefix.$newname;
606
$self->{'listcache'}{$key} = $list;
607
$self->put($key, $list);
631
$self->_populateListCache($key);
633
$self->{'listcache'}{$key}{$newval} = 1;
635
$self->_storeListCache($key);
615
643
my $name = shift;
618
if( exists( $self->{'listcache'}{$key} ) )
620
$list = $self->{'listcache'}{$key};
624
$list = $self->get($key);
625
$self->{'listcache'}{$key} = $list;
628
if( defined($list) and length($list) > 0 )
630
if( grep {$name eq $_} split(',', $list) )
645
$self->_populateListCache($key);
646
return $self->{'listcache'}{$key}{$name};
640
652
my $self = shift;
642
654
my $name = shift;
645
if( exists( $self->{'listcache'}{$key} ) )
647
$list = $self->{'listcache'}{$key};
651
$list = $self->get($key);
652
$self->{'listcache'}{$key} = $list;
655
if( defined($list) and length($list) > 0 )
657
my @array = split(',', $list);
659
foreach my $index (0 .. $#array)
661
if( $array[$index] eq $name )
663
splice( @array, $index, 1 );
670
if( scalar(@array) > 0 )
672
$list = join(',', @array);
673
$self->{'listcache'}{$key} = $list;
674
$self->put($key, $list);
679
delete $self->{'listcache'}{$key};
656
$self->_populateListCache($key);
657
if( $self->{'listcache'}{$key}{$name} )
659
delete $self->{'listcache'}{$key}{$name};
662
$self->_storeListCache($key);
671
$self->_populateListCache($key);
672
return keys %{$self->{'listcache'}{$key}};
691
if( $self->{'delay_list_commit'} and
692
defined( $self->{'listcache'} ) )
694
while( my($key, $list) = each %{$self->{'listcache'}} )
696
$self->put($key, join(',', keys %{$list}));