Closed swen4 closed 2 weeks ago
Are you able to share a sample repository showing the issue? It seems to be related the type or quantity of data you are storing.
@ryanmitchell I'll try to set up an example repository the coming days. Although my current project only has one "term" inside the taxonomy I'm trying to display, and only 17 terms in total, spread across other taxonomies. (Wasn't able to display those in Antlers either)
Hmm ok, feels like it might be a recursion issue then.
@ryanmitchell After setting up an example repo, and doing some debugging, it seems to be related to how many entries my collection has.
I could not reproduce the issue with a fresh dataset, so instead of that I did an experiment:
Thanks for the update - sounds similar to: https://github.com/statamic/eloquent-driver/issues/344
As I mentioned there we have a bottleneck in the code here: statamic/eloquent-driver@master/src/Taxonomies/TermQueryBuilder.php#L213-L258
I'm not entirely sure how (or even if) we can avoid it while keeping parity with the stache driver.
As a temporary workaround I created a custom Antlers tag that gets the data we need Probably not a great solution, but it works well enough for our use case:
<?php
namespace App\Tags;
use Statamic\Facades\Entry;
use Statamic\Facades\Term;
use Statamic\Tags\Tags;
/**
* Workaround for performance issues with {{ termname }} Antlers tags.
*/
class RawTerms extends Tags
{
/**
* The {{ raw_terms:* }} wildcard method handler.
*
* @return string|array
*/
public function wildcard($method)
{
if ($method === 'index') {
return '';
}
$taxonomy = $method;
$entry = $this->context->value('id') ? Entry::find($this->context->value('id')) : null;
if (!$entry) {
return '';
}
$terms = $entry->get($taxonomy);
if (!is_array($terms)) {
$terms = [$terms];
}
if ($terms && count($terms)) {
$results = collect($terms)->map(function ($slug) use ($taxonomy) {
$term = Term::query()
->where('taxonomy', $taxonomy)
->where('slug', $slug)
->first();
return $term ? $term->toAugmentedArray() : null;
})->filter()->all();
return $results;
}
return [];
}
}
Thanks, I'm going to try and take another look at the problem query in the next week or so.
@swen4 I've done a quick PR here for a potential change - https://github.com/statamic/eloquent-driver/pull/345 can you let me know if that helps with your performance issue at all?
@ryanmitchell I did some tests on my database with ~10k articles and noted the loading times:
Seems like the performance hit is negligible now, awesome!
That’s promising. It’s the number of terms that now matter - not the number of entries. I’m working on the assumption those will always be fewer than entries.
Bug description
When trying to query terms from a Terms Field in Antlers, my application times out. I have taxonomies and terms configured to use the eloquent driver in my
config/statamic/eloquent-driver.php
file.The terms work fine in the control panel, it's only when I try to query the terms through Antlers that the issue arises.
When I revert the eloquent-driver for Terms to "file" the issue doesn't happen.
How to reproduce
config/statamic/eloquent-driver.php
.php please eloquent:import-taxonomies
and "yes" to both promptsLogs
Environment
Additional details
No response