Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsing large calendar files. #473

Open
8633brown opened this issue Oct 12, 2019 · 0 comments · May be fixed by #474
Open

Parsing large calendar files. #473

8633brown opened this issue Oct 12, 2019 · 0 comments · May be fixed by #474

Comments

@8633brown
Copy link

8633brown commented Oct 12, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant