vobject icon indicating copy to clipboard operation
vobject copied to clipboard

Parsing large calendar files.

Open 8633brown opened this issue 5 years ago • 0 comments

I'm having to parse a large VCalendar file with over 2000 VEvents and i was looking for a method to help reduce the size of the resulting VObject\Document as the resulting object is overkill for what i'm actually using it for. Most of the events in the file are in the past and i only need the events from present to around a month in the future. I was struggling to find any way to do it with the current project. I've ended up adding these few lines to VObject\MimeDir::parseDocument

        $loLim = new \DateTime('now');
        $hiLim = new \DateTime('4 weeks');
        while (true) {
            // Reading until we hit END:
            $line = $this->readLine();
            if ('END:' === strtoupper(substr($line, 0, 4))) {
                break;
            }
            $result = $this->parseLine($line);
            if ($result) {
                if ($result instanceof Component\VEvent && ! $result->RRULE) {
                    if (
                        $result->DTSTART->getDateTime() > $hiLim ||
                        $result->DTEND->getDateTime() < $loLim 
                    ) {
                        continue;
                    }
                }
                $this->root->add($result);
            }
        }

Preferably the $hiLim and $loLim values would be passed in as parameters. Using this it reduced the memory usage in my case from over 30MB to less than 5MB.

I imagine this method is pretty crude as for handling timezones. I'm not sure how else this could be best implemented.

This is just an example of what I've done and was wondering if this is functionality that could benefit the project? Or if there's functionality already included that i just cant find.

E: also needs to include recurring events.

8633brown avatar Oct 12 '19 02:10 8633brown