-import { literal, Op, QueryTypes, Transaction } from 'sequelize'
+import { col, fn, literal, Op, QueryTypes, Transaction, where } from 'sequelize'
import {
AllowNull,
BelongsTo,
unique: true
},
{
- fields: [ 'preferredUsername', 'serverId' ],
+ fields: [ fn('lower', col('preferredUsername')), 'serverId' ],
+ name: 'actor_preferred_username_lower_server_id',
unique: true,
where: {
serverId: {
}
},
{
- fields: [ 'preferredUsername' ],
+ fields: [ fn('lower', col('preferredUsername')) ],
+ name: 'actor_preferred_username_lower',
unique: true,
where: {
serverId: null
// ---------------------------------------------------------------------------
+ static wherePreferredUsername (preferredUsername: string, colName = 'preferredUsername') {
+ return where(fn('lower', col(colName)), preferredUsername.toLowerCase())
+ }
+
+ // ---------------------------------------------------------------------------
+
static async load (id: number): Promise<MActor> {
const actorServer = await getServerActor()
if (id === actorServer.id) return actorServer
const fun = () => {
const query = {
where: {
- preferredUsername,
- serverId: null
+ [Op.and]: [
+ this.wherePreferredUsername(preferredUsername, '"ActorModel"."preferredUsername"'),
+ {
+ serverId: null
+ }
+ ]
},
transaction
}
const query = {
attributes: [ 'url' ],
where: {
- preferredUsername,
- serverId: null
+ [Op.and]: [
+ this.wherePreferredUsername(preferredUsername),
+ {
+ serverId: null
+ }
+ ]
},
transaction
}
}
return ModelCache.Instance.doCache({
- cacheType: 'local-actor-name',
+ cacheType: 'local-actor-url',
key: preferredUsername,
// The server actor never change, so we can easily cache it
whitelist: () => preferredUsername === SERVER_ACTOR_NAME,
static loadByNameAndHost (preferredUsername: string, host: string): Promise<MActorFull> {
const query = {
- where: {
- preferredUsername
- },
+ where: this.wherePreferredUsername(preferredUsername, '"ActorModel"."preferredUsername"'),
include: [
{
model: ServerModel,