2
0
mirror of https://github.com/fhem/fhem-mirror.git synced 2025-03-10 09:16:53 +00:00

57_Calender: optimization for speed

git-svn-id: https://svn.fhem.de/fhem/trunk@14282 2b470e98-0d58-463d-a4d8-8e2adae1ed80
This commit is contained in:
borisneubert 2017-05-14 15:45:28 +00:00
parent 9e57a9b371
commit 1520cb6a2b
2 changed files with 29 additions and 29 deletions

View File

@ -1,5 +1,6 @@
# Add changes at the top of the list. Keep it in ASCII, and 80-char wide. # Add changes at the top of the list. Keep it in ASCII, and 80-char wide.
# Do not insert empty lines here, update check depends on it. # Do not insert empty lines here, update check depends on it.
- update: 57_Calender: optimization for speed
- bugfix: 36_Vallox: Changed way multireadings are updated. - bugfix: 36_Vallox: Changed way multireadings are updated.
- feature: 49_TBot_List: sorting entries plus corrections - feature: 49_TBot_List: sorting entries plus corrections
- bugfix: 73_PRESENCE: fix restart of threshold counter after FHEM restart - bugfix: 73_PRESENCE: fix restart of threshold counter after FHEM restart

View File

@ -876,23 +876,26 @@ sub addproperty($$) {
my ($key,$parts,$parameter); my ($key,$parts,$parameter);
if($line =~ /^([\w\d\-]+)(;(.*))?:(.*)$/) { if($line =~ /^([\w\d\-]+)(;(.*))?:(.*)$/) {
$key= $1; $key= $1;
$parts= defined($3) ? $3 : ""; $parts= $3 // "";
$parameter= defined($4) ? $4 : ""; $parameter= $4 // "";
} else { } else {
return; return;
} }
return unless($key); return unless($key);
#main::Debug "addproperty for key $key";
# ignore some properties # ignore some properties
my @ignores= qw(TRANSP STATUS ATTENDEE); # commented out: it is faster to add the property than to do the check
return if($key ~~ @ignores); # return if(($key eq "ATTENDEE") or ($key eq "TRANSP") or ($key eq "STATUS"));
return if($key =~ /^X-/); return if(substr($key,0,2) eq "^X-");
if(($key eq "EXDATE") or ($key eq "RDATE")) { if(($key eq "RDATE") or ($key eq "EXDATE")) {
#main::Debug "addproperty for dates";
# handle multiple properties # handle multiple properties
my @values; my @values;
@values= @{$self->values($key)} if($self->hasKey($key)); @values= @{$self->values($key)} if($self->hasKey($key));
push @values, $parameter; push @values, $parameter;
#main::Debug "addproperty pushed parameter $parameter to key $key";
$self->{properties}{$key}= { $self->{properties}{$key}= {
multiple => 1, multiple => 1,
VALUES => \@values, VALUES => \@values,
@ -908,35 +911,35 @@ sub addproperty($$) {
} }
sub parse($$) { sub parse($$) {
my ($self,@ical)= @_; my ($self,$ics)= @_;
return $self->parseSub(0, @ical);
my @ical= split /\R/, $ics;
return $self->parseSub(0, \@ical);
} }
sub parseSub($$$) { sub parseSub($$$) {
my ($self,$ln,@ical)= @_; my ($self,$ln,$icalref)= @_;
my $len= scalar @$icalref;
#main::Debug "lines= $len";
#main::Debug "ENTER @ $ln"; #main::Debug "ENTER @ $ln";
while($ln<$#ical) { while($ln< $len) {
my $line= $ical[$ln]; my $line= $$icalref[$ln];
chomp $line;
$line =~ s/[\x0D]$//; # chomp will not remove the CR
$ln++; $ln++;
# check for and handle continuation lines (4.1 on page 12) # check for and handle continuation lines (4.1 on page 12)
while($ln<$#ical) { while($ln< $len) {
my $line1= $ical[$ln]; my $line1= $$icalref[$ln];
last unless($line1 =~ /^\s(.*)/); last if(substr($line1,0,1) ne " ");
$line.= $1; $line.= substr($line1,1);
chomp $line;
$line =~ s/[\x0D]$//; # chomp will not remove the CR
$ln++; $ln++;
}; };
#main::Debug "$ln: $line"; #main::Debug "$ln: $line";
next if($line eq ""); # ignore empty line next if($line eq ""); # ignore empty line
last if($line =~ m/^END:.*$/); last if(substr($line,0,4) eq "END:");
if($line =~ m/^BEGIN:(.*)$/) { if(substr($line,0,6) eq "BEGIN:") {
my $entry= ICal::Entry->new($1); my $entry= ICal::Entry->new(substr($line,6));
$entry->{ln}= $ln; $entry->{ln}= $ln;
push @{$self->{entries}}, $entry; push @{$self->{entries}}, $entry;
$ln= $entry->parseSub($ln,@ical); $ln= $entry->parseSub($ln,$icalref);
} else { } else {
$self->addproperty($line); $self->addproperty($line);
} }
@ -2201,13 +2204,9 @@ sub Calendar_UpdateCalendar($$$$) {
Log3 $hash, 4, "Calendar $name: parsing data"; Log3 $hash, 4, "Calendar $name: parsing data";
#main::Debug "Calendar $name: parsing data"; #main::Debug "Calendar $name: parsing data";
# we remove disturbing CRs from the file
$ics =~ s/[\r\n]+/\n/g;
# we parse the calendar into a recursive ICal::Entry structure # we parse the calendar into a recursive ICal::Entry structure
my $ical= ICal::Entry->new("root"); my $ical= ICal::Entry->new("root");
$ical->parse(split("\n",$ics)); $ical->parse($ics);
#main::Debug "*** Result:"; #main::Debug "*** Result:";
#main::Debug $ical->asString(); #main::Debug $ical->asString();
@ -2223,7 +2222,7 @@ sub Calendar_UpdateCalendar($$$$) {
else { else {
Log3 $hash, 4, "Calendar $name: unzipping data"; Log3 $hash, 4, "Calendar $name: unzipping data";
$ics = Compress::Zlib::memGunzip($ics); $ics = Compress::Zlib::memGunzip($ics);
$ical->parse(split("\n",$ics)); $ical->parse($ics);
@entries= @{$ical->{entries}}; @entries= @{$ical->{entries}};
} }
}; };