-
-
Notifications
You must be signed in to change notification settings - Fork 349
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
[feature] Page through accounts as moderator #2881
Conversation
a64c4d4
to
88a9265
Compare
} | ||
|
||
if err := q.Scan(ctx, &accountIDs); err != nil { | ||
if err := q.Scan(ctx, &accountIDs, new([]string)); err != nil { |
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.
how come we need this second argument? i thought we were only selecting the one column here 🤔
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.
We are selecting account_id but also selecting domain_username as part of that query, and unfortunately bun doesn't really know what to do if you don't provide a second array to soak up the domain_username values, unless there's a way around it I haven't spotted.
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.
i'm wondering whether using a generated column that you also create an index on might work out a bit better (e.g. https://www.sqlite.org/gencol.html)
so generate a column name domain_username
and then in both the sqlite and postgres queries can just do SELECT id FROM accounts WHERE (...) ORDER domain_username ASC/DESC
. it's a column that would probably come in handy in other areas too i'm sure 🤔
b6f594a
to
e28b05b
Compare
Hmm just gotta make a few fixes for postgres before squerging this. |
} else { | ||
// Create a subquery for | ||
// Postgres to reuse. | ||
subQ = a.db.NewRaw( |
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.
passing in this subquery multiple times in postgres, does it calculate it each and every time? or is it possible to use a temporary variable for it or something?
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.
As far as I can tell, it's computed only once because of the expression index I also added:
Index expressions are relatively expensive to maintain, because the derived expression(s) must be computed for each row insertion and non-HOT update. However, the index expressions are not recomputed during an indexed search, since they are already stored in the index. In both examples above, the system sees the query as just WHERE indexedcolumn = 'constant' and so the speed of the search is equivalent to any other simple index query. Thus, indexes on expressions are useful when retrieval speed is more important than insertion and update speed.
-- https://www.postgresql.org/docs/current/indexes-expressional.html
So I think we should be fine. I tried doing this a few different ways (using WITH, or as subqueries), but Postgres doesn't offer the same flexibility SQLite does, so this ended up being (I think) the best way of doing it, even though the queries themselves end up looking a bit silly because of the expression re-use.
* [feature] Page through accounts as moderator * aaaaa * use COLLATE "C" for Postgres to ensure same ordering as SQLite * fix typo, test paging up * don't show moderation / info for our instance acct
* [feature] Page through accounts as moderator * aaaaa * use COLLATE "C" for Postgres to ensure same ordering as SQLite * fix typo, test paging up * don't show moderation / info for our instance acct
Description
This pull request implements paging through accounts alphabetically via the admin API, as opposed to paging by creation date. To accomplish this, a new index is added on a concatenation of
[domain]/@[username]
.Paging is also implemented in the frontend, so admins can page up and down through accounts in the settings panel.
Checklist
Please put an x inside each checkbox to indicate that you've read and followed it:
[ ]
->[x]
If this is a documentation change, only the first checkbox must be filled (you can delete the others if you want).
go fmt ./...
andgolangci-lint run
.