spatie / laravel-medialibrary

Associate files with Eloquent models
https://spatie.be/docs/laravel-medialibrary
MIT License
5.78k stars 1.08k forks source link

Use Lazy Collection for artisan commands #3670

Closed patrickomeara closed 4 months ago

patrickomeara commented 4 months ago

Following on from #3669...

The artisan commands are the only place that the getBy*() and getOrphans*() methods are used within the package.

As MediaRepository is not yet configurable the only impacted users for this change would be those that replace it in the container, or those that resolve it and expect Eloquent Collections from thegetBy*() and getOrphans*() methods.

Alternatively, we could introduce an interface to bind to and a repository_class configuration option, and ship a CursorMediaRepository that returns LazyCollections from the getBy*() and getOrphans*() methods. I initially started down this path however, I can't think of a reason that the artisan commands shouldn't always use LazyCollection.

If it's decided that the latter option is better, we should take the opportunity of a major release to create a MediaCollections\MediaRepositories namespace.

I'm open to feedback.

freekmurze commented 4 months ago

For now, I don't mind those queries are defined multiple times. I'll re-evaluate this when creating a new major version.