Skip to content

Commit

Permalink
Merge pull request #1 from yunochi/remote_avatar_deco_cache
Browse files Browse the repository at this point in the history
Remote avatar deco cache
  • Loading branch information
yunochi authored Dec 1, 2023
2 parents d3cbfb0 + 0c85ada commit b936482
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "misskey",
"version": "2023.11.1+munochi.4",
"version": "2023.11.1+munochi.5",
"codename": "nasubi",
"repository": {
"type": "git",
Expand Down
7 changes: 6 additions & 1 deletion packages/backend/src/core/AvatarDecorationService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {IsNull} from "typeorm";
@Injectable()
export class AvatarDecorationService implements OnApplicationShutdown {
public cache: MemorySingleCache<MiAvatarDecoration[]>;
public cacheWithRemote: MemorySingleCache<MiAvatarDecoration[]>;

constructor(
@Inject(DI.config)
Expand All @@ -44,6 +45,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
private httpRequestService: HttpRequestService,
) {
this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);
this.cacheWithRemote = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);

this.redisForSub.on('message', this.onMessage);
}
Expand Down Expand Up @@ -177,8 +179,10 @@ export class AvatarDecorationService implements OnApplicationShutdown {
};
if (existingDecoration == null) {
await this.create(decorationData);
this.cacheWithRemote.delete();
} else {
await this.update(existingDecoration.id, decorationData);
this.cacheWithRemote.delete();
}
const findDecoration = await this.avatarDecorationsRepository.findOneBy({
host: userHost,
Expand Down Expand Up @@ -212,11 +216,12 @@ export class AvatarDecorationService implements OnApplicationShutdown {
public async getAll(noCache = false, withRemote = false): Promise<MiAvatarDecoration[]> {
if (noCache) {
this.cache.delete();
this.cacheWithRemote.delete();
}
if (!withRemote) {
return this.cache.fetch(() => this.avatarDecorationsRepository.find({ where: { host: IsNull() } }));
} else {
return this.cache.fetch(() => this.avatarDecorationsRepository.find());
return this.cacheWithRemote.fetch(() => this.avatarDecorationsRepository.find());
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/backend/src/core/entities/UserEntityService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class UserEntityService implements OnModuleInit {
host: user.host,
avatarUrl: user.avatarUrl ?? this.getIdenticonUrl(user),
avatarBlurhash: user.avatarBlurhash,
avatarDecorations: user.avatarDecorations.length > 0 ? this.avatarDecorationService.getAll(true, true).then(decorations => user.avatarDecorations.filter(ud => decorations.some(d => d.id === ud.id)).map(ud => ({
avatarDecorations: user.avatarDecorations.length > 0 ? this.avatarDecorationService.getAll(false, true).then(decorations => user.avatarDecorations.filter(ud => decorations.some(d => d.id === ud.id)).map(ud => ({
id: ud.id,
angle: ud.angle || undefined,
flipH: ud.flipH || undefined,
Expand Down

0 comments on commit b936482

Please sign in to comment.