summaryrefslogtreecommitdiff
path: root/packages/backend/src/core
diff options
context:
space:
mode:
authorsyuilo <Syuilotan@yahoo.co.jp>2023-04-11 15:51:07 +0900
committerGitHub <noreply@github.com>2023-04-11 15:51:07 +0900
commit75b28d6782d9e1a37dd40444fbccffdf4331737a (patch)
tree1b6a1b33ca19a579d7d24d92fef4bfb05ae1e86e /packages/backend/src/core
parentMerge pull request #10543 from misskey-dev/develop (diff)
parentfix(client): noPaging: true with gallery/featured (diff)
downloadmisskey-75b28d6782d9e1a37dd40444fbccffdf4331737a.tar.gz
misskey-75b28d6782d9e1a37dd40444fbccffdf4331737a.tar.bz2
misskey-75b28d6782d9e1a37dd40444fbccffdf4331737a.zip
Merge pull request #10578 from misskey-dev/develop
Release: 13.11.2
Diffstat (limited to 'packages/backend/src/core')
-rw-r--r--packages/backend/src/core/AntennaService.ts10
-rw-r--r--packages/backend/src/core/CacheService.ts8
-rw-r--r--packages/backend/src/core/CustomEmojiService.ts8
-rw-r--r--packages/backend/src/core/GlobalEventService.ts6
-rw-r--r--packages/backend/src/core/MetaService.ts8
-rw-r--r--packages/backend/src/core/NoteCreateService.ts2
-rw-r--r--packages/backend/src/core/NotificationService.ts3
-rw-r--r--packages/backend/src/core/PushNotificationService.ts26
-rw-r--r--packages/backend/src/core/RoleService.ts8
-rw-r--r--packages/backend/src/core/WebhookService.ts8
10 files changed, 50 insertions, 37 deletions
diff --git a/packages/backend/src/core/AntennaService.ts b/packages/backend/src/core/AntennaService.ts
index 35266ac16d..02e0b455fd 100644
--- a/packages/backend/src/core/AntennaService.ts
+++ b/packages/backend/src/core/AntennaService.ts
@@ -27,8 +27,8 @@ export class AntennaService implements OnApplicationShutdown {
@Inject(DI.redis)
private redisClient: Redis.Redis,
- @Inject(DI.redisForPubsub)
- private redisForPubsub: Redis.Redis,
+ @Inject(DI.redisForSub)
+ private redisForSub: Redis.Redis,
@Inject(DI.mutingsRepository)
private mutingsRepository: MutingsRepository,
@@ -52,12 +52,12 @@ export class AntennaService implements OnApplicationShutdown {
this.antennasFetched = false;
this.antennas = [];
- this.redisForPubsub.on('message', this.onRedisMessage);
+ this.redisForSub.on('message', this.onRedisMessage);
}
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
- this.redisForPubsub.off('message', this.onRedisMessage);
+ this.redisForSub.off('message', this.onRedisMessage);
}
@bindThis
@@ -95,7 +95,7 @@ export class AntennaService implements OnApplicationShutdown {
this.redisClient.xadd(
`antennaTimeline:${antenna.id}`,
'MAXLEN', '~', '200',
- `${this.idService.parse(note.id).date.getTime()}-*`,
+ '*',
'note', note.id);
this.globalEventService.publishAntennaStream(antenna.id, 'note', note);
diff --git a/packages/backend/src/core/CacheService.ts b/packages/backend/src/core/CacheService.ts
index d74f3e8788..561face5c3 100644
--- a/packages/backend/src/core/CacheService.ts
+++ b/packages/backend/src/core/CacheService.ts
@@ -27,8 +27,8 @@ export class CacheService implements OnApplicationShutdown {
@Inject(DI.redis)
private redisClient: Redis.Redis,
- @Inject(DI.redisForPubsub)
- private redisForPubsub: Redis.Redis,
+ @Inject(DI.redisForSub)
+ private redisForSub: Redis.Redis,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@@ -116,7 +116,7 @@ export class CacheService implements OnApplicationShutdown {
fromRedisConverter: (value) => new Set(JSON.parse(value)),
});
- this.redisForPubsub.on('message', this.onMessage);
+ this.redisForSub.on('message', this.onMessage);
}
@bindThis
@@ -167,6 +167,6 @@ export class CacheService implements OnApplicationShutdown {
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
- this.redisForPubsub.off('message', this.onMessage);
+ this.redisForSub.off('message', this.onMessage);
}
}
diff --git a/packages/backend/src/core/CustomEmojiService.ts b/packages/backend/src/core/CustomEmojiService.ts
index dc365986fe..3de936dd65 100644
--- a/packages/backend/src/core/CustomEmojiService.ts
+++ b/packages/backend/src/core/CustomEmojiService.ts
@@ -43,12 +43,8 @@ export class CustomEmojiService {
lifetime: 1000 * 60 * 30, // 30m
memoryCacheLifetime: 1000 * 60 * 3, // 3m
fetcher: () => this.emojisRepository.find({ where: { host: IsNull() } }).then(emojis => new Map(emojis.map(emoji => [emoji.name, emoji]))),
- toRedisConverter: (value) => JSON.stringify(value.values()),
- fromRedisConverter: (value) => {
- // 原因不明だが配列以外が入ってくることがあるため
- if (!Array.isArray(JSON.parse(value))) return undefined;
- return new Map(JSON.parse(value).map((x: Emoji) => [x.name, x]));
- }, // TODO: Date型の変換
+ toRedisConverter: (value) => JSON.stringify(Array.from(value.values())),
+ fromRedisConverter: (value) => new Map(JSON.parse(value).map((x: Emoji) => [x.name, x])), // TODO: Date型の変換
});
}
diff --git a/packages/backend/src/core/GlobalEventService.ts b/packages/backend/src/core/GlobalEventService.ts
index 25c064a2b4..9f4de5f985 100644
--- a/packages/backend/src/core/GlobalEventService.ts
+++ b/packages/backend/src/core/GlobalEventService.ts
@@ -26,8 +26,8 @@ export class GlobalEventService {
@Inject(DI.config)
private config: Config,
- @Inject(DI.redis)
- private redisClient: Redis.Redis,
+ @Inject(DI.redisForPub)
+ private redisForPub: Redis.Redis,
) {
}
@@ -37,7 +37,7 @@ export class GlobalEventService {
{ type: type, body: null } :
{ type: type, body: value };
- this.redisClient.publish(this.config.host, JSON.stringify({
+ this.redisForPub.publish(this.config.host, JSON.stringify({
channel: channel,
message: message,
}));
diff --git a/packages/backend/src/core/MetaService.ts b/packages/backend/src/core/MetaService.ts
index 2b6160c82e..1322927c2c 100644
--- a/packages/backend/src/core/MetaService.ts
+++ b/packages/backend/src/core/MetaService.ts
@@ -14,8 +14,8 @@ export class MetaService implements OnApplicationShutdown {
private intervalId: NodeJS.Timer;
constructor(
- @Inject(DI.redisForPubsub)
- private redisForPubsub: Redis.Redis,
+ @Inject(DI.redisForSub)
+ private redisForSub: Redis.Redis,
@Inject(DI.db)
private db: DataSource,
@@ -33,7 +33,7 @@ export class MetaService implements OnApplicationShutdown {
}, 1000 * 60 * 5);
}
- this.redisForPubsub.on('message', this.onMessage);
+ this.redisForSub.on('message', this.onMessage);
}
@bindThis
@@ -122,6 +122,6 @@ export class MetaService implements OnApplicationShutdown {
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
clearInterval(this.intervalId);
- this.redisForPubsub.off('message', this.onMessage);
+ this.redisForSub.off('message', this.onMessage);
}
}
diff --git a/packages/backend/src/core/NoteCreateService.ts b/packages/backend/src/core/NoteCreateService.ts
index 5c4d13f178..fb7ee7080a 100644
--- a/packages/backend/src/core/NoteCreateService.ts
+++ b/packages/backend/src/core/NoteCreateService.ts
@@ -329,7 +329,7 @@ export class NoteCreateService implements OnApplicationShutdown {
this.redisClient.xadd(
`channelTimeline:${data.channel.id}`,
'MAXLEN', '~', '1000',
- `${this.idService.parse(note.id).date.getTime()}-*`,
+ '*',
'note', note.id);
}
diff --git a/packages/backend/src/core/NotificationService.ts b/packages/backend/src/core/NotificationService.ts
index c44dddea41..6691c42836 100644
--- a/packages/backend/src/core/NotificationService.ts
+++ b/packages/backend/src/core/NotificationService.ts
@@ -66,6 +66,7 @@ export class NotificationService implements OnApplicationShutdown {
@bindThis
private postReadAllNotifications(userId: User['id']) {
this.globalEventService.publishMainStream(userId, 'readAllNotifications');
+ this.pushNotificationService.pushNotification(userId, 'readAllNotifications', undefined);
}
@bindThis
@@ -99,7 +100,7 @@ export class NotificationService implements OnApplicationShutdown {
const redisIdPromise = this.redisClient.xadd(
`notificationTimeline:${notifieeId}`,
'MAXLEN', '~', '300',
- `${this.idService.parse(notification.id).date.getTime()}-*`,
+ '*',
'data', JSON.stringify(notification));
const packed = await this.notificationEntityService.pack(notification, notifieeId, {});
diff --git a/packages/backend/src/core/PushNotificationService.ts b/packages/backend/src/core/PushNotificationService.ts
index 69020f7e84..9b44cf6413 100644
--- a/packages/backend/src/core/PushNotificationService.ts
+++ b/packages/backend/src/core/PushNotificationService.ts
@@ -1,12 +1,14 @@
import { Inject, Injectable } from '@nestjs/common';
import push from 'web-push';
+import Redis from 'ioredis';
import { DI } from '@/di-symbols.js';
import type { Config } from '@/config.js';
import type { Packed } from '@/misc/json-schema';
import { getNoteSummary } from '@/misc/get-note-summary.js';
-import type { SwSubscriptionsRepository } from '@/models/index.js';
+import type { SwSubscription, SwSubscriptionsRepository } from '@/models/index.js';
import { MetaService } from '@/core/MetaService.js';
import { bindThis } from '@/decorators.js';
+import { RedisKVCache } from '@/misc/cache.js';
// Defined also packages/sw/types.ts#L13
type PushNotificationsTypes = {
@@ -15,6 +17,7 @@ type PushNotificationsTypes = {
antenna: { id: string, name: string };
note: Packed<'Note'>;
};
+ 'readAllNotifications': undefined;
};
// Reduce length because push message servers have character limits
@@ -40,15 +43,27 @@ function truncateBody<T extends keyof PushNotificationsTypes>(type: T, body: Pus
@Injectable()
export class PushNotificationService {
+ private subscriptionsCache: RedisKVCache<SwSubscription[]>;
+
constructor(
@Inject(DI.config)
private config: Config,
+ @Inject(DI.redis)
+ private redisClient: Redis.Redis,
+
@Inject(DI.swSubscriptionsRepository)
private swSubscriptionsRepository: SwSubscriptionsRepository,
private metaService: MetaService,
) {
+ this.subscriptionsCache = new RedisKVCache<SwSubscription[]>(this.redisClient, 'userSwSubscriptions', {
+ lifetime: 1000 * 60 * 60 * 1, // 1h
+ memoryCacheLifetime: 1000 * 60 * 3, // 3m
+ fetcher: (key) => this.swSubscriptionsRepository.findBy({ userId: key }),
+ toRedisConverter: (value) => JSON.stringify(value),
+ fromRedisConverter: (value) => JSON.parse(value),
+ });
}
@bindThis
@@ -62,12 +77,13 @@ export class PushNotificationService {
meta.swPublicKey,
meta.swPrivateKey);
- // Fetch
- const subscriptions = await this.swSubscriptionsRepository.findBy({
- userId: userId,
- });
+ const subscriptions = await this.subscriptionsCache.fetch(userId);
for (const subscription of subscriptions) {
+ if ([
+ 'readAllNotifications',
+ ].includes(type) && !subscription.sendReadMessage) continue;
+
const pushSubscription = {
endpoint: subscription.endpoint,
keys: {
diff --git a/packages/backend/src/core/RoleService.ts b/packages/backend/src/core/RoleService.ts
index c8ebe1adb7..77645e3f06 100644
--- a/packages/backend/src/core/RoleService.ts
+++ b/packages/backend/src/core/RoleService.ts
@@ -64,8 +64,8 @@ export class RoleService implements OnApplicationShutdown {
public static NotAssignedError = class extends Error {};
constructor(
- @Inject(DI.redisForPubsub)
- private redisForPubsub: Redis.Redis,
+ @Inject(DI.redisForSub)
+ private redisForSub: Redis.Redis,
@Inject(DI.usersRepository)
private usersRepository: UsersRepository,
@@ -87,7 +87,7 @@ export class RoleService implements OnApplicationShutdown {
this.rolesCache = new MemorySingleCache<Role[]>(1000 * 60 * 60 * 1);
this.roleAssignmentByUserIdCache = new MemoryKVCache<RoleAssignment[]>(1000 * 60 * 60 * 1);
- this.redisForPubsub.on('message', this.onMessage);
+ this.redisForSub.on('message', this.onMessage);
}
@bindThis
@@ -400,6 +400,6 @@ export class RoleService implements OnApplicationShutdown {
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
- this.redisForPubsub.off('message', this.onMessage);
+ this.redisForSub.off('message', this.onMessage);
}
}
diff --git a/packages/backend/src/core/WebhookService.ts b/packages/backend/src/core/WebhookService.ts
index 85594f8557..926115613b 100644
--- a/packages/backend/src/core/WebhookService.ts
+++ b/packages/backend/src/core/WebhookService.ts
@@ -13,14 +13,14 @@ export class WebhookService implements OnApplicationShutdown {
private webhooks: Webhook[] = [];
constructor(
- @Inject(DI.redisForPubsub)
- private redisForPubsub: Redis.Redis,
+ @Inject(DI.redisForSub)
+ private redisForSub: Redis.Redis,
@Inject(DI.webhooksRepository)
private webhooksRepository: WebhooksRepository,
) {
//this.onMessage = this.onMessage.bind(this);
- this.redisForPubsub.on('message', this.onMessage);
+ this.redisForSub.on('message', this.onMessage);
}
@bindThis
@@ -82,6 +82,6 @@ export class WebhookService implements OnApplicationShutdown {
@bindThis
public onApplicationShutdown(signal?: string | undefined) {
- this.redisForPubsub.off('message', this.onMessage);
+ this.redisForSub.off('message', this.onMessage);
}
}