I've a large 'Posts' table (~60k entries) and a "Replies" table (~500k entries). I wish to iterate over the post and replies and then conditionally add them to the sitemap file.
I'm making use of the cursor() method in Laravel 6 but it blows off even before it does anything meaningful. Here's what I have -
// Job
$posts = Post::with('replies')->cursor();
foreach( $posts as $post) {
// Calculate the word count in posts and associated replies
// If it's below the threshold, continue the loop
// Add the $post->url to sitemap
}
Now the moment I run it, I get following error -
PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 7510792 bytes) in
$posts = Post::with('replies')->cursor()->each(function($post) {
// Calculate the word count in posts and associated replies
// If it's below the threshold, continue the loop
// Add the $post->url to sitemap
});
This is just based on the fact that all examples uses collection methods in the official documentation (with the exception of the part that actually echos the data after filtering it)
I could very well be wrong, but if you test it and it just works, I might be correct :)