perf(calendar): don't allocate and copy all children for each time we call _filterComponent:

Improving the filtering of the calender objects, keeping a global static of the array of tags
that are allowed. And using removeChildren to prevent the need of a full copy while we iterate
over it.
This commit is contained in:
Emily Kooistra
2025-06-24 20:07:45 +02:00
committed by QHivert
parent f48f27c812
commit 481a9bf1de
+12 -7
View File
@@ -65,6 +65,9 @@
#import "iCalRepeatableEntityObject+SOGo.h"
#import "SOGoCalendarComponent.h"
static NSArray *allowed_tags = nil;
@implementation SOGoCalendarComponent
+ (SOGoWebDAVAclManager *) webdavAclManager
@@ -210,7 +213,6 @@
SOGoUser *calendarOwner;
NSEnumerator *children;
CardElement *element;
NSArray *tags;
int classification;
@@ -231,22 +233,25 @@
summary = [self labelForKey: [NSString stringWithFormat: @"%@_class%d",
type, classification]
inContext: context];
tags = [NSArray arrayWithObjects: @"DTSTAMP", @"DTSTART", @"DTEND", @"DUE", @"EXDATE", @"EXRULE", @"RRULE", @"RECURRENCE-ID", nil];
if(!allowed_tags)
allowed_tags = [[NSArray arrayWithObjects: @"DTSTAMP", @"DTSTART", @"DTEND", @"DUE", @"EXDATE", @"EXRULE", @"RRULE", @"RECURRENCE-ID", nil] retain];
uid = [[component uid] asCryptedPassUsingScheme: @"ssha256"
withSalt: [[settings userPublicSalt] dataUsingEncoding: NSASCIIStringEncoding]
andEncoding: encHex
keyPath: nil];
children = [[[[component children] copy] autorelease] objectEnumerator];
children = [[component children] objectEnumerator];
NSMutableArray *to_remove = [NSMutableArray arrayWithCapacity: 8];
while ((element = [children nextObject]))
{
tag = [element tag];
if (![tags containsObject: [tag uppercaseString]])
[component removeChild: element];
if (![allowed_tags containsObject: [tag uppercaseString]])
[to_remove addObject: element];
}
[component removeChildren: to_remove];
[component setSummary: summary];
[component setUid: uid];
}