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

Streamed annotation responses #946

Open
mzur opened this issue Oct 10, 2024 · 0 comments
Open

Streamed annotation responses #946

mzur opened this issue Oct 10, 2024 · 0 comments

Comments

@mzur
Copy link
Member

mzur commented Oct 10, 2024

We had a case of a long video where the request to get all video annotations ran into the memory limit. To avoid this we can send a streamed JSON response and fetch the annotations lazily in chunks. Here is a proof of concept for the VideoAnnotationController:

public function index(Request $request, $id)
{
    $video = Video::findOrFail($id);
    $this->authorize('access', $video);

    $user = $request->user();
    $session = $video->volume->getActiveAnnotationSession($user);
    $load = ['labels.label', 'labels.user'];

    if ($session) {
        return $session->getVolumeFileAnnotations($video, $user)->load($load);
    }

    $yieldAnnotations = function () use ($video, $load): \Generator {
        foreach ($video->annotations()->with($load)->lazy() as $annotation) {
            yield $annotation;
        }
    };

    return response()->streamJson($yieldAnnotations());
}

The same could be done in the ImageAnnotationController.

In the proof of concept above the streaming does not work if there is an active annotation session. The getVolumeFileAnnotations() method of an annotation session has to be updated to support streaming like that.

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

No branches or pull requests

1 participant