Merge branch 'develop' into flash-sticky
This commit is contained in:
commit
36e8919e94
14
CHANGELOG.md
14
CHANGELOG.md
|
@ -1,3 +1,15 @@
|
||||||
|
## Unreleased
|
||||||
|
|
||||||
|
### General
|
||||||
|
-
|
||||||
|
|
||||||
|
### Client
|
||||||
|
-
|
||||||
|
|
||||||
|
### Server
|
||||||
|
-
|
||||||
|
|
||||||
|
|
||||||
## 2024.8.0
|
## 2024.8.0
|
||||||
|
|
||||||
### General
|
### General
|
||||||
|
@ -34,6 +46,8 @@
|
||||||
- Fix: 無制限にストリーミングのチャンネルに接続できる問題を修正
|
- Fix: 無制限にストリーミングのチャンネルに接続できる問題を修正
|
||||||
- Fix: ベースロールのポリシーを変更した際にモデログに記録されないのを修正
|
- Fix: ベースロールのポリシーを変更した際にモデログに記録されないのを修正
|
||||||
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/700)
|
(Cherry-picked from https://github.com/MisskeyIO/misskey/pull/700)
|
||||||
|
- Fix: Prevent memory leak from memory caches (#14310)
|
||||||
|
- Fix: More reliable memory cache eviction (#14311)
|
||||||
|
|
||||||
## 2024.7.0
|
## 2024.7.0
|
||||||
|
|
||||||
|
|
|
@ -2316,6 +2316,7 @@ _pages:
|
||||||
eyeCatchingImageSet: "Set thumbnail"
|
eyeCatchingImageSet: "Set thumbnail"
|
||||||
eyeCatchingImageRemove: "Delete thumbnail"
|
eyeCatchingImageRemove: "Delete thumbnail"
|
||||||
chooseBlock: "Add a block"
|
chooseBlock: "Add a block"
|
||||||
|
enterSectionTitle: "Enter a section title"
|
||||||
selectType: "Select a type"
|
selectType: "Select a type"
|
||||||
contentBlocks: "Content"
|
contentBlocks: "Content"
|
||||||
inputBlocks: "Input"
|
inputBlocks: "Input"
|
||||||
|
@ -2499,7 +2500,10 @@ _moderationLogTypes:
|
||||||
createAbuseReportNotificationRecipient: "Create a recipient for abuse reports"
|
createAbuseReportNotificationRecipient: "Create a recipient for abuse reports"
|
||||||
updateAbuseReportNotificationRecipient: "Update recipients for abuse reports"
|
updateAbuseReportNotificationRecipient: "Update recipients for abuse reports"
|
||||||
deleteAbuseReportNotificationRecipient: "Delete a recipient for abuse reports"
|
deleteAbuseReportNotificationRecipient: "Delete a recipient for abuse reports"
|
||||||
|
deleteAccount: "Delete the account"
|
||||||
|
deletePage: "Delete the page"
|
||||||
deleteFlash: "Delete Play"
|
deleteFlash: "Delete Play"
|
||||||
|
deleteGalleryPost: "Delete the gallery post"
|
||||||
_fileViewer:
|
_fileViewer:
|
||||||
title: "File details"
|
title: "File details"
|
||||||
type: "File type"
|
type: "File type"
|
||||||
|
|
|
@ -2316,6 +2316,7 @@ _pages:
|
||||||
eyeCatchingImageSet: "设置封面图片"
|
eyeCatchingImageSet: "设置封面图片"
|
||||||
eyeCatchingImageRemove: "删除封面图片"
|
eyeCatchingImageRemove: "删除封面图片"
|
||||||
chooseBlock: "添加块"
|
chooseBlock: "添加块"
|
||||||
|
enterSectionTitle: "输入会话标题"
|
||||||
selectType: "选择类型"
|
selectType: "选择类型"
|
||||||
contentBlocks: "内容"
|
contentBlocks: "内容"
|
||||||
inputBlocks: "输入"
|
inputBlocks: "输入"
|
||||||
|
@ -2499,8 +2500,10 @@ _moderationLogTypes:
|
||||||
createAbuseReportNotificationRecipient: "新建了举报通知"
|
createAbuseReportNotificationRecipient: "新建了举报通知"
|
||||||
updateAbuseReportNotificationRecipient: "更新了举报通知"
|
updateAbuseReportNotificationRecipient: "更新了举报通知"
|
||||||
deleteAbuseReportNotificationRecipient: "删除了举报通知"
|
deleteAbuseReportNotificationRecipient: "删除了举报通知"
|
||||||
|
deleteAccount: "删除了账户"
|
||||||
deletePage: "删除了页面"
|
deletePage: "删除了页面"
|
||||||
deleteFlash: "删除了 Play"
|
deleteFlash: "删除了 Play"
|
||||||
|
deleteGalleryPost: "删除了图库稿件"
|
||||||
_fileViewer:
|
_fileViewer:
|
||||||
title: "文件信息"
|
title: "文件信息"
|
||||||
type: "文件类型"
|
type: "文件类型"
|
||||||
|
|
|
@ -2316,6 +2316,7 @@ _pages:
|
||||||
eyeCatchingImageSet: "設定封面影像"
|
eyeCatchingImageSet: "設定封面影像"
|
||||||
eyeCatchingImageRemove: "刪除封面影像"
|
eyeCatchingImageRemove: "刪除封面影像"
|
||||||
chooseBlock: "新增方塊"
|
chooseBlock: "新增方塊"
|
||||||
|
enterSectionTitle: "輸入區段的標題"
|
||||||
selectType: "選擇類型"
|
selectType: "選擇類型"
|
||||||
contentBlocks: "內容"
|
contentBlocks: "內容"
|
||||||
inputBlocks: "輸入"
|
inputBlocks: "輸入"
|
||||||
|
@ -2499,6 +2500,10 @@ _moderationLogTypes:
|
||||||
createAbuseReportNotificationRecipient: "建立接收檢舉的通知對象"
|
createAbuseReportNotificationRecipient: "建立接收檢舉的通知對象"
|
||||||
updateAbuseReportNotificationRecipient: "更新接收檢舉的通知對象"
|
updateAbuseReportNotificationRecipient: "更新接收檢舉的通知對象"
|
||||||
deleteAbuseReportNotificationRecipient: "刪除接收檢舉的通知對象"
|
deleteAbuseReportNotificationRecipient: "刪除接收檢舉的通知對象"
|
||||||
|
deleteAccount: "刪除帳戶"
|
||||||
|
deletePage: "刪除頁面"
|
||||||
|
deleteFlash: "刪除 Play"
|
||||||
|
deleteGalleryPost: "刪除相簿的貼文"
|
||||||
_fileViewer:
|
_fileViewer:
|
||||||
title: "檔案詳細資訊"
|
title: "檔案詳細資訊"
|
||||||
type: "檔案類型 "
|
type: "檔案類型 "
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "misskey",
|
"name": "misskey",
|
||||||
"version": "2024.8.0-rc.3",
|
"version": "2024.8.0",
|
||||||
"codename": "nasubi",
|
"codename": "nasubi",
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
|
|
|
@ -29,7 +29,7 @@ export class AvatarDecorationService implements OnApplicationShutdown {
|
||||||
private moderationLogService: ModerationLogService,
|
private moderationLogService: ModerationLogService,
|
||||||
private globalEventService: GlobalEventService,
|
private globalEventService: GlobalEventService,
|
||||||
) {
|
) {
|
||||||
this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30);
|
this.cache = new MemorySingleCache<MiAvatarDecoration[]>(1000 * 60 * 30); // 30s
|
||||||
|
|
||||||
this.redisForSub.on('message', this.onMessage);
|
this.redisForSub.on('message', this.onMessage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,10 +56,10 @@ export class CacheService implements OnApplicationShutdown {
|
||||||
) {
|
) {
|
||||||
//this.onMessage = this.onMessage.bind(this);
|
//this.onMessage = this.onMessage.bind(this);
|
||||||
|
|
||||||
this.userByIdCache = new MemoryKVCache<MiUser>(Infinity);
|
this.userByIdCache = new MemoryKVCache<MiUser>(1000 * 60 * 5); // 5m
|
||||||
this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null>(Infinity);
|
this.localUserByNativeTokenCache = new MemoryKVCache<MiLocalUser | null>(1000 * 60 * 5); // 5m
|
||||||
this.localUserByIdCache = new MemoryKVCache<MiLocalUser>(Infinity);
|
this.localUserByIdCache = new MemoryKVCache<MiLocalUser>(1000 * 60 * 5); // 5m
|
||||||
this.uriPersonCache = new MemoryKVCache<MiUser | null>(Infinity);
|
this.uriPersonCache = new MemoryKVCache<MiUser | null>(1000 * 60 * 5); // 5m
|
||||||
|
|
||||||
this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', {
|
this.userProfileCache = new RedisKVCache<MiUserProfile>(this.redisClient, 'userProfile', {
|
||||||
lifetime: 1000 * 60 * 30, // 30m
|
lifetime: 1000 * 60 * 30, // 30m
|
||||||
|
@ -135,14 +135,14 @@ export class CacheService implements OnApplicationShutdown {
|
||||||
if (user == null) {
|
if (user == null) {
|
||||||
this.userByIdCache.delete(body.id);
|
this.userByIdCache.delete(body.id);
|
||||||
this.localUserByIdCache.delete(body.id);
|
this.localUserByIdCache.delete(body.id);
|
||||||
for (const [k, v] of this.uriPersonCache.cache.entries()) {
|
for (const [k, v] of this.uriPersonCache.entries) {
|
||||||
if (v.value?.id === body.id) {
|
if (v.value?.id === body.id) {
|
||||||
this.uriPersonCache.delete(k);
|
this.uriPersonCache.delete(k);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
this.userByIdCache.set(user.id, user);
|
this.userByIdCache.set(user.id, user);
|
||||||
for (const [k, v] of this.uriPersonCache.cache.entries()) {
|
for (const [k, v] of this.uriPersonCache.entries) {
|
||||||
if (v.value?.id === user.id) {
|
if (v.value?.id === user.id) {
|
||||||
this.uriPersonCache.set(k, user);
|
this.uriPersonCache.set(k, user);
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,7 +24,7 @@ const parseEmojiStrRegexp = /^([-\w]+)(?:@([\w.-]+))?$/;
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class CustomEmojiService implements OnApplicationShutdown {
|
export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
private cache: MemoryKVCache<MiEmoji | null>;
|
private emojisCache: MemoryKVCache<MiEmoji | null>;
|
||||||
public localEmojisCache: RedisSingleCache<Map<string, MiEmoji>>;
|
public localEmojisCache: RedisSingleCache<Map<string, MiEmoji>>;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -40,7 +40,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
private moderationLogService: ModerationLogService,
|
private moderationLogService: ModerationLogService,
|
||||||
private globalEventService: GlobalEventService,
|
private globalEventService: GlobalEventService,
|
||||||
) {
|
) {
|
||||||
this.cache = new MemoryKVCache<MiEmoji | null>(1000 * 60 * 60 * 12);
|
this.emojisCache = new MemoryKVCache<MiEmoji | null>(1000 * 60 * 60 * 12); // 12h
|
||||||
|
|
||||||
this.localEmojisCache = new RedisSingleCache<Map<string, MiEmoji>>(this.redisClient, 'localEmojis', {
|
this.localEmojisCache = new RedisSingleCache<Map<string, MiEmoji>>(this.redisClient, 'localEmojis', {
|
||||||
lifetime: 1000 * 60 * 30, // 30m
|
lifetime: 1000 * 60 * 30, // 30m
|
||||||
|
@ -334,7 +334,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
host,
|
host,
|
||||||
})) ?? null;
|
})) ?? null;
|
||||||
|
|
||||||
const emoji = await this.cache.fetch(`${name} ${host}`, queryOrNull);
|
const emoji = await this.emojisCache.fetch(`${name} ${host}`, queryOrNull);
|
||||||
|
|
||||||
if (emoji == null) return null;
|
if (emoji == null) return null;
|
||||||
return emoji.publicUrl || emoji.originalUrl; // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ)
|
return emoji.publicUrl || emoji.originalUrl; // || emoji.originalUrl してるのは後方互換性のため(publicUrlはstringなので??はだめ)
|
||||||
|
@ -361,7 +361,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async prefetchEmojis(emojis: { name: string; host: string | null; }[]): Promise<void> {
|
public async prefetchEmojis(emojis: { name: string; host: string | null; }[]): Promise<void> {
|
||||||
const notCachedEmojis = emojis.filter(emoji => this.cache.get(`${emoji.name} ${emoji.host}`) == null);
|
const notCachedEmojis = emojis.filter(emoji => this.emojisCache.get(`${emoji.name} ${emoji.host}`) == null);
|
||||||
const emojisQuery: any[] = [];
|
const emojisQuery: any[] = [];
|
||||||
const hosts = new Set(notCachedEmojis.map(e => e.host));
|
const hosts = new Set(notCachedEmojis.map(e => e.host));
|
||||||
for (const host of hosts) {
|
for (const host of hosts) {
|
||||||
|
@ -376,7 +376,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
select: ['name', 'host', 'originalUrl', 'publicUrl'],
|
select: ['name', 'host', 'originalUrl', 'publicUrl'],
|
||||||
}) : [];
|
}) : [];
|
||||||
for (const emoji of _emojis) {
|
for (const emoji of _emojis) {
|
||||||
this.cache.set(`${emoji.name} ${emoji.host}`, emoji);
|
this.emojisCache.set(`${emoji.name} ${emoji.host}`, emoji);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -401,7 +401,7 @@ export class CustomEmojiService implements OnApplicationShutdown {
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
this.cache.dispose();
|
this.emojisCache.dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -35,7 +35,7 @@ export class RelayService {
|
||||||
private createSystemUserService: CreateSystemUserService,
|
private createSystemUserService: CreateSystemUserService,
|
||||||
private apRendererService: ApRendererService,
|
private apRendererService: ApRendererService,
|
||||||
) {
|
) {
|
||||||
this.relaysCache = new MemorySingleCache<MiRelay[]>(1000 * 60 * 10);
|
this.relaysCache = new MemorySingleCache<MiRelay[]>(1000 * 60 * 10); // 10m
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -127,10 +127,8 @@ export class RoleService implements OnApplicationShutdown, OnModuleInit {
|
||||||
private moderationLogService: ModerationLogService,
|
private moderationLogService: ModerationLogService,
|
||||||
private fanoutTimelineService: FanoutTimelineService,
|
private fanoutTimelineService: FanoutTimelineService,
|
||||||
) {
|
) {
|
||||||
//this.onMessage = this.onMessage.bind(this);
|
this.rolesCache = new MemorySingleCache<MiRole[]>(1000 * 60 * 60); // 1h
|
||||||
|
this.roleAssignmentByUserIdCache = new MemoryKVCache<MiRoleAssignment[]>(1000 * 60 * 5); // 5m
|
||||||
this.rolesCache = new MemorySingleCache<MiRole[]>(1000 * 60 * 60 * 1);
|
|
||||||
this.roleAssignmentByUserIdCache = new MemoryKVCache<MiRoleAssignment[]>(1000 * 60 * 60 * 1);
|
|
||||||
|
|
||||||
this.redisForSub.on('message', this.onMessage);
|
this.redisForSub.on('message', this.onMessage);
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,7 @@ export class UserKeypairService implements OnApplicationShutdown {
|
||||||
) {
|
) {
|
||||||
this.cache = new RedisKVCache<MiUserKeypair>(this.redisClient, 'userKeypair', {
|
this.cache = new RedisKVCache<MiUserKeypair>(this.redisClient, 'userKeypair', {
|
||||||
lifetime: 1000 * 60 * 60 * 24, // 24h
|
lifetime: 1000 * 60 * 60 * 24, // 24h
|
||||||
memoryCacheLifetime: Infinity,
|
memoryCacheLifetime: 1000 * 60 * 60, // 1h
|
||||||
fetcher: (key) => this.userKeypairsRepository.findOneByOrFail({ userId: key }),
|
fetcher: (key) => this.userKeypairsRepository.findOneByOrFail({ userId: key }),
|
||||||
toRedisConverter: (value) => JSON.stringify(value),
|
toRedisConverter: (value) => JSON.stringify(value),
|
||||||
fromRedisConverter: (value) => JSON.parse(value),
|
fromRedisConverter: (value) => JSON.parse(value),
|
||||||
|
|
|
@ -54,8 +54,8 @@ export class ApDbResolverService implements OnApplicationShutdown {
|
||||||
private cacheService: CacheService,
|
private cacheService: CacheService,
|
||||||
private apPersonService: ApPersonService,
|
private apPersonService: ApPersonService,
|
||||||
) {
|
) {
|
||||||
this.publicKeyCache = new MemoryKVCache<MiUserPublickey | null>(Infinity);
|
this.publicKeyCache = new MemoryKVCache<MiUserPublickey | null>(1000 * 60 * 60 * 12); // 12h
|
||||||
this.publicKeyByUserIdCache = new MemoryKVCache<MiUserPublickey | null>(Infinity);
|
this.publicKeyByUserIdCache = new MemoryKVCache<MiUserPublickey | null>(1000 * 60 * 60 * 12); // 12h
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -7,23 +7,23 @@ import * as Redis from 'ioredis';
|
||||||
import { bindThis } from '@/decorators.js';
|
import { bindThis } from '@/decorators.js';
|
||||||
|
|
||||||
export class RedisKVCache<T> {
|
export class RedisKVCache<T> {
|
||||||
private redisClient: Redis.Redis;
|
private readonly lifetime: number;
|
||||||
private name: string;
|
private readonly memoryCache: MemoryKVCache<T>;
|
||||||
private lifetime: number;
|
private readonly fetcher: (key: string) => Promise<T>;
|
||||||
private memoryCache: MemoryKVCache<T>;
|
private readonly toRedisConverter: (value: T) => string;
|
||||||
private fetcher: (key: string) => Promise<T>;
|
private readonly fromRedisConverter: (value: string) => T | undefined;
|
||||||
private toRedisConverter: (value: T) => string;
|
|
||||||
private fromRedisConverter: (value: string) => T | undefined;
|
|
||||||
|
|
||||||
constructor(redisClient: RedisKVCache<T>['redisClient'], name: RedisKVCache<T>['name'], opts: {
|
constructor(
|
||||||
|
private redisClient: Redis.Redis,
|
||||||
|
private name: string,
|
||||||
|
opts: {
|
||||||
lifetime: RedisKVCache<T>['lifetime'];
|
lifetime: RedisKVCache<T>['lifetime'];
|
||||||
memoryCacheLifetime: number;
|
memoryCacheLifetime: number;
|
||||||
fetcher: RedisKVCache<T>['fetcher'];
|
fetcher: RedisKVCache<T>['fetcher'];
|
||||||
toRedisConverter: RedisKVCache<T>['toRedisConverter'];
|
toRedisConverter: RedisKVCache<T>['toRedisConverter'];
|
||||||
fromRedisConverter: RedisKVCache<T>['fromRedisConverter'];
|
fromRedisConverter: RedisKVCache<T>['fromRedisConverter'];
|
||||||
}) {
|
},
|
||||||
this.redisClient = redisClient;
|
) {
|
||||||
this.name = name;
|
|
||||||
this.lifetime = opts.lifetime;
|
this.lifetime = opts.lifetime;
|
||||||
this.memoryCache = new MemoryKVCache(opts.memoryCacheLifetime);
|
this.memoryCache = new MemoryKVCache(opts.memoryCacheLifetime);
|
||||||
this.fetcher = opts.fetcher;
|
this.fetcher = opts.fetcher;
|
||||||
|
@ -55,7 +55,13 @@ export class RedisKVCache<T> {
|
||||||
|
|
||||||
const cached = await this.redisClient.get(`kvcache:${this.name}:${key}`);
|
const cached = await this.redisClient.get(`kvcache:${this.name}:${key}`);
|
||||||
if (cached == null) return undefined;
|
if (cached == null) return undefined;
|
||||||
return this.fromRedisConverter(cached);
|
|
||||||
|
const value = this.fromRedisConverter(cached);
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.memoryCache.set(key, value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -66,6 +72,10 @@ export class RedisKVCache<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* キャッシュがあればそれを返し、無ければfetcherを呼び出して結果をキャッシュ&返します
|
* キャッシュがあればそれを返し、無ければfetcherを呼び出して結果をキャッシュ&返します
|
||||||
|
* This awaits the call to Redis to ensure that the write succeeded, which is important for a few reasons:
|
||||||
|
* * Other code uses this to synchronize changes between worker processes. A failed write can internally de-sync the cluster.
|
||||||
|
* * Without an `await`, consecutive calls could race. An unlucky race could result in the older write overwriting the newer value.
|
||||||
|
* * Not awaiting here makes the entire cache non-consistent. The prevents many possible uses.
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async fetch(key: string): Promise<T> {
|
public async fetch(key: string): Promise<T> {
|
||||||
|
@ -77,14 +87,14 @@ export class RedisKVCache<T> {
|
||||||
|
|
||||||
// Cache MISS
|
// Cache MISS
|
||||||
const value = await this.fetcher(key);
|
const value = await this.fetcher(key);
|
||||||
this.set(key, value);
|
await this.set(key, value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async refresh(key: string) {
|
public async refresh(key: string) {
|
||||||
const value = await this.fetcher(key);
|
const value = await this.fetcher(key);
|
||||||
this.set(key, value);
|
await this.set(key, value);
|
||||||
|
|
||||||
// TODO: イベント発行して他プロセスのメモリキャッシュも更新できるようにする
|
// TODO: イベント発行して他プロセスのメモリキャッシュも更新できるようにする
|
||||||
}
|
}
|
||||||
|
@ -101,23 +111,23 @@ export class RedisKVCache<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export class RedisSingleCache<T> {
|
export class RedisSingleCache<T> {
|
||||||
private redisClient: Redis.Redis;
|
private readonly lifetime: number;
|
||||||
private name: string;
|
private readonly memoryCache: MemorySingleCache<T>;
|
||||||
private lifetime: number;
|
private readonly fetcher: () => Promise<T>;
|
||||||
private memoryCache: MemorySingleCache<T>;
|
private readonly toRedisConverter: (value: T) => string;
|
||||||
private fetcher: () => Promise<T>;
|
private readonly fromRedisConverter: (value: string) => T | undefined;
|
||||||
private toRedisConverter: (value: T) => string;
|
|
||||||
private fromRedisConverter: (value: string) => T | undefined;
|
|
||||||
|
|
||||||
constructor(redisClient: RedisSingleCache<T>['redisClient'], name: RedisSingleCache<T>['name'], opts: {
|
constructor(
|
||||||
lifetime: RedisSingleCache<T>['lifetime'];
|
private redisClient: Redis.Redis,
|
||||||
|
private name: string,
|
||||||
|
opts: {
|
||||||
|
lifetime: number;
|
||||||
memoryCacheLifetime: number;
|
memoryCacheLifetime: number;
|
||||||
fetcher: RedisSingleCache<T>['fetcher'];
|
fetcher: RedisSingleCache<T>['fetcher'];
|
||||||
toRedisConverter: RedisSingleCache<T>['toRedisConverter'];
|
toRedisConverter: RedisSingleCache<T>['toRedisConverter'];
|
||||||
fromRedisConverter: RedisSingleCache<T>['fromRedisConverter'];
|
fromRedisConverter: RedisSingleCache<T>['fromRedisConverter'];
|
||||||
}) {
|
},
|
||||||
this.redisClient = redisClient;
|
) {
|
||||||
this.name = name;
|
|
||||||
this.lifetime = opts.lifetime;
|
this.lifetime = opts.lifetime;
|
||||||
this.memoryCache = new MemorySingleCache(opts.memoryCacheLifetime);
|
this.memoryCache = new MemorySingleCache(opts.memoryCacheLifetime);
|
||||||
this.fetcher = opts.fetcher;
|
this.fetcher = opts.fetcher;
|
||||||
|
@ -149,7 +159,13 @@ export class RedisSingleCache<T> {
|
||||||
|
|
||||||
const cached = await this.redisClient.get(`singlecache:${this.name}`);
|
const cached = await this.redisClient.get(`singlecache:${this.name}`);
|
||||||
if (cached == null) return undefined;
|
if (cached == null) return undefined;
|
||||||
return this.fromRedisConverter(cached);
|
|
||||||
|
const value = this.fromRedisConverter(cached);
|
||||||
|
if (value !== undefined) {
|
||||||
|
this.memoryCache.set(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
@ -160,6 +176,10 @@ export class RedisSingleCache<T> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* キャッシュがあればそれを返し、無ければfetcherを呼び出して結果をキャッシュ&返します
|
* キャッシュがあればそれを返し、無ければfetcherを呼び出して結果をキャッシュ&返します
|
||||||
|
* This awaits the call to Redis to ensure that the write succeeded, which is important for a few reasons:
|
||||||
|
* * Other code uses this to synchronize changes between worker processes. A failed write can internally de-sync the cluster.
|
||||||
|
* * Without an `await`, consecutive calls could race. An unlucky race could result in the older write overwriting the newer value.
|
||||||
|
* * Not awaiting here makes the entire cache non-consistent. The prevents many possible uses.
|
||||||
*/
|
*/
|
||||||
@bindThis
|
@bindThis
|
||||||
public async fetch(): Promise<T> {
|
public async fetch(): Promise<T> {
|
||||||
|
@ -171,14 +191,14 @@ export class RedisSingleCache<T> {
|
||||||
|
|
||||||
// Cache MISS
|
// Cache MISS
|
||||||
const value = await this.fetcher();
|
const value = await this.fetcher();
|
||||||
this.set(value);
|
await this.set(value);
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public async refresh() {
|
public async refresh() {
|
||||||
const value = await this.fetcher();
|
const value = await this.fetcher();
|
||||||
this.set(value);
|
await this.set(value);
|
||||||
|
|
||||||
// TODO: イベント発行して他プロセスのメモリキャッシュも更新できるようにする
|
// TODO: イベント発行して他プロセスのメモリキャッシュも更新できるようにする
|
||||||
}
|
}
|
||||||
|
@ -187,22 +207,12 @@ export class RedisSingleCache<T> {
|
||||||
// TODO: メモリ節約のためあまり参照されないキーを定期的に削除できるようにする?
|
// TODO: メモリ節約のためあまり参照されないキーを定期的に削除できるようにする?
|
||||||
|
|
||||||
export class MemoryKVCache<T> {
|
export class MemoryKVCache<T> {
|
||||||
/**
|
private readonly cache = new Map<string, { date: number; value: T; }>();
|
||||||
* データを持つマップ
|
private readonly gcIntervalHandle = setInterval(() => this.gc(), 1000 * 60 * 3); // 3m
|
||||||
* @deprecated これを直接操作するべきではない
|
|
||||||
*/
|
|
||||||
public cache: Map<string, { date: number; value: T; }>;
|
|
||||||
private lifetime: number;
|
|
||||||
private gcIntervalHandle: NodeJS.Timeout;
|
|
||||||
|
|
||||||
constructor(lifetime: MemoryKVCache<never>['lifetime']) {
|
constructor(
|
||||||
this.cache = new Map();
|
private readonly lifetime: number,
|
||||||
this.lifetime = lifetime;
|
) {}
|
||||||
|
|
||||||
this.gcIntervalHandle = setInterval(() => {
|
|
||||||
this.gc();
|
|
||||||
}, 1000 * 60 * 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
/**
|
/**
|
||||||
|
@ -287,27 +297,34 @@ export class MemoryKVCache<T> {
|
||||||
@bindThis
|
@bindThis
|
||||||
public gc(): void {
|
public gc(): void {
|
||||||
const now = Date.now();
|
const now = Date.now();
|
||||||
|
|
||||||
for (const [key, { date }] of this.cache.entries()) {
|
for (const [key, { date }] of this.cache.entries()) {
|
||||||
if ((now - date) > this.lifetime) {
|
// The map is ordered from oldest to youngest.
|
||||||
|
// We can stop once we find an entry that's still active, because all following entries must *also* be active.
|
||||||
|
const age = now - date;
|
||||||
|
if (age < this.lifetime) break;
|
||||||
|
|
||||||
this.cache.delete(key);
|
this.cache.delete(key);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public dispose(): void {
|
public dispose(): void {
|
||||||
clearInterval(this.gcIntervalHandle);
|
clearInterval(this.gcIntervalHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get entries() {
|
||||||
|
return this.cache.entries();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export class MemorySingleCache<T> {
|
export class MemorySingleCache<T> {
|
||||||
private cachedAt: number | null = null;
|
private cachedAt: number | null = null;
|
||||||
private value: T | undefined;
|
private value: T | undefined;
|
||||||
private lifetime: number;
|
|
||||||
|
|
||||||
constructor(lifetime: MemorySingleCache<never>['lifetime']) {
|
constructor(
|
||||||
this.lifetime = lifetime;
|
private lifetime: number,
|
||||||
}
|
) {}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
public set(value: T): void {
|
public set(value: T): void {
|
||||||
|
|
|
@ -45,7 +45,7 @@ export class DeliverProcessorService {
|
||||||
private queueLoggerService: QueueLoggerService,
|
private queueLoggerService: QueueLoggerService,
|
||||||
) {
|
) {
|
||||||
this.logger = this.queueLoggerService.logger.createSubLogger('deliver');
|
this.logger = this.queueLoggerService.logger.createSubLogger('deliver');
|
||||||
this.suspendedHostsCache = new MemorySingleCache<MiInstance[]>(1000 * 60 * 60);
|
this.suspendedHostsCache = new MemorySingleCache<MiInstance[]>(1000 * 60 * 60); // 1h
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -134,7 +134,7 @@ export class NodeinfoServerService {
|
||||||
return document;
|
return document;
|
||||||
};
|
};
|
||||||
|
|
||||||
const cache = new MemorySingleCache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10);
|
const cache = new MemorySingleCache<Awaited<ReturnType<typeof nodeinfo2>>>(1000 * 60 * 10); // 10m
|
||||||
|
|
||||||
fastify.get(nodeinfo2_1path, async (request, reply) => {
|
fastify.get(nodeinfo2_1path, async (request, reply) => {
|
||||||
const base = await cache.fetch(() => nodeinfo2(21));
|
const base = await cache.fetch(() => nodeinfo2(21));
|
||||||
|
|
|
@ -37,7 +37,7 @@ export class AuthenticateService implements OnApplicationShutdown {
|
||||||
|
|
||||||
private cacheService: CacheService,
|
private cacheService: CacheService,
|
||||||
) {
|
) {
|
||||||
this.appCache = new MemoryKVCache<MiApp>(Infinity);
|
this.appCache = new MemoryKVCache<MiApp>(1000 * 60 * 60 * 24 * 7); // 1w
|
||||||
}
|
}
|
||||||
|
|
||||||
@bindThis
|
@bindThis
|
||||||
|
|
|
@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div :class="$style.preview">
|
<div :class="$style.preview">
|
||||||
<div :class="$style.preview__content1">
|
<div>
|
||||||
<MkInput v-model="text">
|
<MkInput v-model="text">
|
||||||
<template #label>Text</template>
|
<template #label>Text</template>
|
||||||
</MkInput>
|
</MkInput>
|
||||||
|
|
|
@ -25,7 +25,7 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<span :class="$style.bodyName">{{ role.name }}</span>
|
<span :class="$style.bodyName">{{ role.name }}</span>
|
||||||
<template v-if="detailed">
|
<template v-if="detailed">
|
||||||
<span v-if="role.target === 'manual'" :class="$style.bodyUsers">{{ role.usersCount }} users</span>
|
<span v-if="role.target === 'manual'" :class="$style.bodyUsers">{{ role.usersCount }} users</span>
|
||||||
<span v-else-if="role.target === 'conditional'" :class="$style.bodyUsers">({{ i18n.ts._role.conditional }})</span>
|
<span v-else-if="role.target === 'conditional'" :class="$style.bodyUsers">? users</span>
|
||||||
</template>
|
</template>
|
||||||
</div>
|
</div>
|
||||||
<div :class="$style.bodyDescription">{{ role.description }}</div>
|
<div :class="$style.bodyDescription">{{ role.description }}</div>
|
||||||
|
|
|
@ -72,10 +72,6 @@ SPDX-License-Identifier: AGPL-3.0-only
|
||||||
<img src="https://avatars.githubusercontent.com/u/4439005?v=4" :class="$style.contributorAvatar">
|
<img src="https://avatars.githubusercontent.com/u/4439005?v=4" :class="$style.contributorAvatar">
|
||||||
<span :class="$style.contributorUsername">@syuilo</span>
|
<span :class="$style.contributorUsername">@syuilo</span>
|
||||||
</a>
|
</a>
|
||||||
<a href="https://github.com/tamaina" target="_blank" :class="$style.contributor">
|
|
||||||
<img src="https://avatars.githubusercontent.com/u/7973572?v=4" :class="$style.contributorAvatar">
|
|
||||||
<span :class="$style.contributorUsername">@tamaina</span>
|
|
||||||
</a>
|
|
||||||
<a href="https://github.com/acid-chicken" target="_blank" :class="$style.contributor">
|
<a href="https://github.com/acid-chicken" target="_blank" :class="$style.contributor">
|
||||||
<img src="https://avatars.githubusercontent.com/u/20679825?v=4" :class="$style.contributorAvatar">
|
<img src="https://avatars.githubusercontent.com/u/20679825?v=4" :class="$style.contributorAvatar">
|
||||||
<span :class="$style.contributorUsername">@acid-chicken</span>
|
<span :class="$style.contributorUsername">@acid-chicken</span>
|
||||||
|
|
|
@ -16,21 +16,57 @@ function containsFocusTrappedElements(el: HTMLElement): boolean {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getZIndex(el: HTMLElement): number {
|
||||||
|
const zIndex = parseInt(window.getComputedStyle(el).zIndex || '0', 10);
|
||||||
|
if (isNaN(zIndex)) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
return zIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getHighestZIndexElement(): { el: HTMLElement; zIndex: number; } | null {
|
||||||
|
let highestZIndexElement: HTMLElement | null = null;
|
||||||
|
let highestZIndex = -Infinity;
|
||||||
|
|
||||||
|
focusTrapElements.forEach((el) => {
|
||||||
|
const zIndex = getZIndex(el);
|
||||||
|
if (zIndex > highestZIndex) {
|
||||||
|
highestZIndex = zIndex;
|
||||||
|
highestZIndexElement = el;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return highestZIndexElement == null ? null : {
|
||||||
|
el: highestZIndexElement,
|
||||||
|
zIndex: highestZIndex,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function releaseFocusTrap(el: HTMLElement): void {
|
function releaseFocusTrap(el: HTMLElement): void {
|
||||||
focusTrapElements.delete(el);
|
focusTrapElements.delete(el);
|
||||||
if (el.inert === true) {
|
if (el.inert === true) {
|
||||||
el.inert = false;
|
el.inert = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const highestZIndexElement = getHighestZIndexElement();
|
||||||
|
|
||||||
if (el.parentElement != null && el !== document.body) {
|
if (el.parentElement != null && el !== document.body) {
|
||||||
el.parentElement.childNodes.forEach((siblingNode) => {
|
el.parentElement.childNodes.forEach((siblingNode) => {
|
||||||
const siblingEl = getHTMLElementOrNull(siblingNode);
|
const siblingEl = getHTMLElementOrNull(siblingNode);
|
||||||
if (!siblingEl) return;
|
if (!siblingEl) return;
|
||||||
if (siblingEl !== el && (focusTrapElements.has(siblingEl) || containsFocusTrappedElements(siblingEl) || focusTrapElements.size === 0)) {
|
if (
|
||||||
|
siblingEl !== el &&
|
||||||
|
(
|
||||||
|
highestZIndexElement == null ||
|
||||||
|
siblingEl === highestZIndexElement.el ||
|
||||||
|
siblingEl.contains(highestZIndexElement.el)
|
||||||
|
)
|
||||||
|
) {
|
||||||
siblingEl.inert = false;
|
siblingEl.inert = false;
|
||||||
} else if (
|
} else if (
|
||||||
focusTrapElements.size > 0 &&
|
highestZIndexElement != null &&
|
||||||
!containsFocusTrappedElements(siblingEl) &&
|
siblingEl !== highestZIndexElement.el &&
|
||||||
!focusTrapElements.has(siblingEl) &&
|
!siblingEl.contains(highestZIndexElement.el) &&
|
||||||
!ignoreElements.includes(siblingEl.tagName.toLowerCase())
|
!ignoreElements.includes(siblingEl.tagName.toLowerCase())
|
||||||
) {
|
) {
|
||||||
siblingEl.inert = true;
|
siblingEl.inert = true;
|
||||||
|
@ -45,9 +81,29 @@ function releaseFocusTrap(el: HTMLElement): void {
|
||||||
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls: boolean, parent: true): void;
|
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls: boolean, parent: true): void;
|
||||||
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls?: boolean, parent?: false): { release: () => void; };
|
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls?: boolean, parent?: false): { release: () => void; };
|
||||||
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls = false, parent = false): { release: () => void; } | void {
|
export function focusTrap(el: HTMLElement, hasInteractionWithOtherFocusTrappedEls = false, parent = false): { release: () => void; } | void {
|
||||||
|
const highestZIndexElement = getHighestZIndexElement();
|
||||||
|
|
||||||
|
const highestZIndex = highestZIndexElement == null ? -Infinity : highestZIndexElement.zIndex;
|
||||||
|
const zIndex = getZIndex(el);
|
||||||
|
|
||||||
|
// If the element has a lower z-index than the highest z-index element, focus trap the highest z-index element instead
|
||||||
|
// Focus trapping for this element will be done in the release function
|
||||||
|
if (!parent && zIndex < highestZIndex) {
|
||||||
|
focusTrapElements.add(el);
|
||||||
|
if (highestZIndexElement) {
|
||||||
|
focusTrap(highestZIndexElement.el, hasInteractionWithOtherFocusTrappedEls);
|
||||||
|
}
|
||||||
|
return {
|
||||||
|
release: () => {
|
||||||
|
releaseFocusTrap(el);
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
if (el.inert === true) {
|
if (el.inert === true) {
|
||||||
el.inert = false;
|
el.inert = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (el.parentElement != null && el !== document.body) {
|
if (el.parentElement != null && el !== document.body) {
|
||||||
el.parentElement.childNodes.forEach((siblingNode) => {
|
el.parentElement.childNodes.forEach((siblingNode) => {
|
||||||
const siblingEl = getHTMLElementOrNull(siblingNode);
|
const siblingEl = getHTMLElementOrNull(siblingNode);
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"name": "misskey-js",
|
"name": "misskey-js",
|
||||||
"version": "2024.8.0-rc.3",
|
"version": "2024.8.0",
|
||||||
"description": "Misskey SDK for JavaScript",
|
"description": "Misskey SDK for JavaScript",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"main": "./built/index.js",
|
"main": "./built/index.js",
|
||||||
|
|
Loading…
Reference in New Issue