-
Notifications
You must be signed in to change notification settings - Fork 92
fix: sort Recently Used Apps by settled transactions #2012
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
base: master
Are you sure you want to change the base?
Conversation
|
Hi, Thanks for the PR. But I still think it's important to know when there was any activity at all, as well as if there was monetary activity. There are also problems with the current solution that simply requesting an invoice (but it not being paid) would count as monetary activity. I think this needs more planning before working on an implementation. |
|
Fair point,it is useful to know when an app was last online/connected, even if it didn't spend anything. To fix the sorting without losing that data, how about we split it into two fields? |
|
I wonder if it is possible already to find these apps by doing a DB query that joins apps on the transaction list? then there's no DB changes needed. (as long as the query is efficient enough) |
|
Oh that's a great point, i hadn't considered using the existing transactions table. |
|
@keshav0479 only settled payments count. I think you can look at the transaction state as the settled constant (in constants.go) |
|
Got it, that makes perfect sense regarding the |
|
@keshav0479 sounds good to me, thanks! |
dc8d2cd to
25c5517
Compare
api/api.go
Outdated
|
|
||
| if orderBy == "" { | ||
| orderBy = "last_used_at" | ||
| var totalCount int64 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is incorrect - counting must be done after filtering.
Also, I would undo your changes and make a new sorting parameter for last_economic_activity or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
or last_settled_transaction maybe
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated! Changed the log field to app_id and added last_settled_transaction as a new sorting option, keeping the original logic intact
25c5517 to
1e5cbd8
Compare
📝 WalkthroughWalkthroughAdds a new ListApps ordering option "last_settled_transaction" that orders apps by the timestamp of their most recent settled transaction, and fixes a log field name in the event handler. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
api/api.go (1)
526-531: Count query may return incorrect results with GROUP BY.When
orderBy == "last_settled_transaction", the query has aGROUP BY apps.idclause. Calling.Model(&db.App{}).Count(&totalCount)on this grouped query may not return the correct total count of apps—it could count the number of groups or behave unexpectedly depending on the database driver.Consider computing the count before applying the grouping/aggregation for the
last_settled_transactioncase, or use a separate unmodified query for counting.🔧 Suggested approach
+ // Count before applying aggregation for last_settled_transaction + countQuery := api.db + if filters.Name != "" { + if api.db.Dialector.Name() == "postgres" { + countQuery = countQuery.Where("name ILIKE ?", filters.Name+"%") + } else { + countQuery = countQuery.Where("name LIKE ?", filters.Name+"%") + } + } + // ... apply other filters to countQuery ... + var totalCount int64 - result := query.Model(&db.App{}).Count(&totalCount) + result := countQuery.Model(&db.App{}).Count(&totalCount)Alternatively, you could clone the query before adding the SELECT/JOIN/GROUP BY clauses and use the clone for counting.
🤖 Fix all issues with AI agents
In `@api/api.go`:
- Around line 514-521: The orderBy string already contains DESC and causes a
duplicated "DESC" in query.Order(orderBy + " DESC"), and NULL
last_transaction_at values need to be ordered to the end; when handling the
last_settled_transaction branch (the block that calls query.Select(...
MAX(transactions.created_at) as last_transaction_at) / Joins(...) /
Group("apps.id")), set orderBy to a value that includes NULL-safe ordering (for
example using COALESCE(last_transaction_at, '1970-01-01') DESC,
apps.last_used_at DESC) and then stop appending " DESC" later — change the final
call to use query.Order(orderBy) (or ensure orderBy contains no direction if you
intend to append " DESC"), so you neither produce duplicate DESC nor leave NULL
last_transaction_at entries unordered.
Description
Fixes #1998
Sorts "Recently Used Apps" by settled transactions instead of
LastUsedAt, so apps that actively move value appear at the top.Changes
LEFT JOINtransactionswherestate = 'SETTLED'and sort byMAX(transactions.created_at).Notes
LastUsedAtstill tracks connection activity (useful for debugging).Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.