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

Add starting-from-id option to regenerate command #2688

Merged
merged 5 commits into from
Dec 17, 2021

Conversation

billypoke
Copy link
Contributor

I have found myself wanting to regenerate recent images, but with potentially thousands of ids to pass as a command option, I thought adding a date option could be useful

@freekmurze
Copy link
Member

freekmurze commented Dec 9, 2021

Could you refactor this option to starting-from-id? This way you still get the behaviour your want, but it's slight more clear and a little bit more flexible.

@freekmurze
Copy link
Member

Could you also update the readme with an example?

@billypoke billypoke changed the title Add after-date option to regenerate command Add starting-from-id option to regenerate command Dec 9, 2021
@billypoke
Copy link
Contributor Author

@freekmurze refactored and documented in the readme. Let me know if you have any other changes

Thanks for taking the time 😄

@billypoke
Copy link
Contributor Author

looks like failing tests now. Seems to be failing on main as well

$mediaIds = $this->getMediaIds();
$noIds = count($mediaIds) === 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This whole bit feel unreadable to me.

Try to start with the special cases (so starting with determining if you should start from an id or model.

Instead of using &&, introduce new helper functions where you don't use && but work with early returns.

Also make it possible to get models that start with an id greater than some id.

@billypoke billypoke force-pushed the feature-regenerate-by-date branch from 02c063c to 93b657b Compare December 11, 2021 16:28
}

return $this->mediaRepository->getByIds($mediaIds);
return $this->mediaRepository->all();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is what you were suggesting? Handle the special cases first, then fall back to ids or all media

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems better now.

A case that isn't handled well now is we you pass both modelType and startingFromId. Right now that startingFromId will be ignored.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should work without refactoring the existing methods to pass the builder instead of the result and chaining everything depending on the args and options.

I didn't think passing ids and modelType at the same time would make a ton of sense as a use case as the ids may not belong to the passed type.

@freekmurze freekmurze merged commit cde0659 into spatie:main Dec 17, 2021
@freekmurze
Copy link
Member

Thanks!

@billypoke billypoke deleted the feature-regenerate-by-date branch December 17, 2021 13:21
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 this pull request may close these issues.

2 participants