Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -508,10 +508,16 @@ func (api *api) ListApps(limit uint64, offset uint64, filters ListAppsFilters, o
orderBy = "last_used_at"
}
if orderBy == "last_used_at" {
// when ordering by last used at, apps with last_used_at is NULL should be ordered last
orderBy = "last_used_at IS NULL, " + orderBy
}

if orderBy == "last_settled_transaction" {
query = query.Select("apps.*, MAX(transactions.created_at) as last_transaction_at").
Joins("LEFT JOIN transactions ON transactions.app_id = apps.id AND transactions.state = ?", constants.TRANSACTION_STATE_SETTLED).
Group("apps.id")
orderBy = "last_transaction_at IS NULL, last_transaction_at DESC, apps.last_used_at"
}

query = query.Order(orderBy + " DESC")

if limit == 0 {
Expand Down
3 changes: 1 addition & 2 deletions nip47/event_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,9 @@ func (svc *nip47Service) HandleEvent(ctx context.Context, pool nostrmodels.Simpl
err = svc.db.Model(&app).Update("last_used_at", &now).Error
if err != nil {
logger.Logger.WithFields(logrus.Fields{
"it": app.ID,
"app_id": app.ID,
}).WithError(err).Error("Failed to update app last used time")
}

logger.Logger.WithFields(logrus.Fields{
"requestEventNostrId": event.ID,
"eventKind": event.Kind,
Expand Down
Loading