fix: don't specify FOR clause for index hint

- I made a mistake when specifying the `FOR` clause for the index hint,
I read it as being an required argument by XORM. The [MariaDB
documention](https://mariadb.com/kb/en/use-index/) tells that it
defaults to the `FOR JOIN` clause hence why I specified `JOIN` (As can
be seen in the previous PR's SQL analyze I didn't specify the `FOR`
clause). However apparently there seems to be some wizardy going on as
we need to tell MariaDB to use this index for the `ORDER BY` clause to
actually force MariaDB to use this index over the `updated_unix` index.
However because it's not actually required by XORM to specify this
value I leave this empty as mariadb is apparently smart enough to figure
out for which type we want to use this index.
- TL;DR make this index hint actually effective for MariaDB.
- Ref: #6146
This commit is contained in:
Gusted 2024-12-06 22:13:17 +01:00
parent e248179333
commit da333382e1
No known key found for this signature in database
GPG key ID: FD821B732837125F

View file

@ -113,7 +113,7 @@ func getNotifications(ctx *context.Context) {
sess := db.GetEngine(ctx).Table("notification")
if setting.Database.Type.IsMySQL() {
sess = sess.IndexHint("USE", "JOIN", "IDX_notification_user_id")
sess = sess.IndexHint("USE", "", "IDX_notification_user_id")
}
sess.Where("user_id = ?", ctx.Doer.ID).
And("status = ? OR status = ?", status, activities_model.NotificationStatusPinned).