Skip to content

fix: erroneous query generation on currency log search#1440

Open
perappu wants to merge 2 commits intolk-arpg:developfrom
perappu:pr/fix-currency-log-search
Open

fix: erroneous query generation on currency log search#1440
perappu wants to merge 2 commits intolk-arpg:developfrom
perappu:pr/fix-currency-log-search

Conversation

@perappu
Copy link
Copy Markdown

@perappu perappu commented Mar 9, 2026

When calling getCurrencyLogs(), the way the SQL generates currently is:

select * from `currencies_log` where (`sender_type` = ? and `sender_id` = ? and `log_type` not in (?, ?, ?, ?)) or (`recipient_type` = ? and `recipient_id` = ? and `log_type` != ?) order by `id` desc

...which, when chained with additional where clauses in the search function, causes some odd display behavior at times (users reported some currencies not showing at all, not showing logs where users transferred them currency, strange ordering, etc). You can see it when searching for a specific user within someone's currency logs here:

select * from `currencies_log` where ((`sender_type` = ? and `sender_id` = ? and `log_type` not in (?, ?, ?, ?)) or (`recipient_type` = ? and `recipient_id` = ? and `log_type` != ?)) and (`sender_id` = ? or `recipient_id` = ?) order by `id` desc

This PR creates additional parentheses in the SQL so chained where()'s are properly handled:

select * from `currencies_log` where ((`sender_type` = ? and `sender_id` = ? and `log_type` not in (?, ?, ?, ?)) or (`recipient_type` = ? and `recipient_id` = ? and `log_type` != ?)) order by `id` desc

So now, when searching for a user:

select * from `currencies_log` where ((`sender_type` = ? and `sender_id` = ? and `log_type` not in (?, ?, ?, ?)) or (`recipient_type` = ? and `recipient_id` = ? and `log_type` != ?)) and ((`sender_id` = ?) or (`recipient_id` = ?)) order by `id` desc

I also applied the same fix to characters for consistency's sake (maybe somebody will add search there someday). Also don't ask me why the intval()s were needed, I'm not fully sure either, but it was handling weird without them, lol.

This would theoretically also be an issue on v3, but it never happens because getCurrencyLogs() returns a collection and not a query.

@itinerare itinerare added bug Something isn't working needs review Pull requests that are pending community review labels Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working needs review Pull requests that are pending community review

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants