buildUserMatchQuery(on:requester:search:favorersOnly:sort:limit:)
private func buildUserMatchQuery(
on req: Request,
requester: UserCacheData,
search: String,
favorersOnly: Bool,
sort: UserMatchSort?,
limit: Int
) async throws -> [User]
Builds the user-name match query: search substring + block exclusion, optional
?favorers=true filter, and optional ?sort= (currently favorites: favorites first, then username).
When sort is .favorites, this can’t be a single ORM query: there’s no ORM-level way to sort
by “is this user one of the requester’s favorites” without a raw-SQL sort expression. Instead, this
runs the favorited and non-favorited matches as two ordinary, separately-sorted-and-capped queries and
concatenates them, which reproduces “favorites first, then everyone else, alphabetical within each
group” without needing a custom SQL fragment.
-
Declaration
Swift
func baseQuery() -> QueryBuilder<User>
View on GitHub