Closed canny[bot] closed 2 years ago
This issue has been linked to a Canny post: Buffer Size Error :tada:
It looks like the query is generated by prepareQuery()
via getByEmail()
, which does not actually use the "additional emails" column (it may be used elsewhere).
Interestingly, if the email doesn't match a primary email address for the donor there is a subsequent query that looks at the additional_email
meta, see getByAdditionalEmail()
using a direct query of the give_donormeta
table.
The method prepareQuery()
is only called in four locations:
public function queryById(int $donorId): ModelQueryBuilder
{
return $this->prepareQuery()
->where('id', $donorId);
}
public function getByWpUserId(int $userId)
{
...
return $this->prepareQuery()
->where('user_id', $userId)
->get();
}
public function getByEmail(string $email)
{
$donorObjectByPrimaryEmail = $this->prepareQuery()
->where('email', $email)
->get();
...
return $donorObjectByPrimaryEmail;
}
public static function query(): ModelQueryBuilder
{
return give()->donors->prepareQuery();
}
The last of which, Donor::query()
, being the most concerning because it is intended to be extended for bespoke queries.
Using PHPStorm I'm not actually seeing any direct use of Donor::query()
.
That said, I think it may be safe to remove the additional_emails
column SELECT
from the prepared query, as it isn't used anywhere. While this would technically be a breaking change, being that we have not publicized the new Models will documentation the risk is low.
@kjohnson the additional_email
column is being used directly by the Donor instance model to check if email exists and associated crud functionality. I think the root of the problem is how we're grabbing that column (this would be the same for any columns that have the same key), not necessarily that we're including it in the query.
Here is the PR that introduced this: https://github.com/impress-org/givewp/pull/6273
I think if we can optimize this query, we won't need to worry about same key queries in the future.
I see now where the SELECT
column is being added to the Donor model, which is used.
I'm leaning towards not pre-loading meta with multiple values (rows) and having those fetched separately. This is actually how getByAdditionalEmail()
works, interestingly.
We have a handful of reports of users receiving the following error: Out of sort memory, consider increasing server sort buffer size. This error is stopping the acceptance of donations.
The current workaround is to have users asking their hosting providers to increase buffer size to 2M.
https://givewp.canny.io/admin/board/bug-reports/p/buffer-size-error
Visuals
Additional Context