mirror of
https://git.joinsharkey.org/Sharkey/Sharkey.git
synced 2024-11-27 07:43:09 +02:00
perf(server): disable some antenna features to improve performance
This commit is contained in:
parent
ff19640171
commit
9320c1699a
3 changed files with 19 additions and 19 deletions
|
@ -1,17 +1,26 @@
|
||||||
import { Antenna } from '@/models/entities/antenna.js';
|
import { Antenna } from '@/models/entities/antenna.js';
|
||||||
import { Note } from '@/models/entities/note.js';
|
import { Note } from '@/models/entities/note.js';
|
||||||
import { User } from '@/models/entities/user.js';
|
import { User } from '@/models/entities/user.js';
|
||||||
import { UserListJoinings, UserGroupJoinings } from '@/models/index.js';
|
import { UserListJoinings, UserGroupJoinings, Blockings } from '@/models/index.js';
|
||||||
import { getFullApAccount } from './convert-host.js';
|
import { getFullApAccount } from './convert-host.js';
|
||||||
import * as Acct from '@/misc/acct.js';
|
import * as Acct from '@/misc/acct.js';
|
||||||
import { Packed } from './schema.js';
|
import { Packed } from './schema.js';
|
||||||
|
import { Cache } from './cache.js';
|
||||||
|
|
||||||
|
const blockingCache = new Cache<User['id'][]>(1000 * 60 * 5);
|
||||||
|
|
||||||
|
// NOTE: フォローしているユーザーのノート、リストのユーザーのノート、グループのユーザーのノート指定はパフォーマンス上の理由で無効になっている
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* noteUserFollowers / antennaUserFollowing はどちらか一方が指定されていればよい
|
* noteUserFollowers / antennaUserFollowing はどちらか一方が指定されていればよい
|
||||||
*/
|
*/
|
||||||
export async function checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise<boolean> {
|
export async function checkHitAntenna(antenna: Antenna, note: (Note | Packed<'Note'>), noteUser: { id: User['id']; username: string; host: string | null; }, noteUserFollowers?: User['id'][], antennaUserFollowing?: User['id'][]): Promise<boolean> {
|
||||||
if (note.visibility === 'specified') return false;
|
if (note.visibility === 'specified') return false;
|
||||||
|
|
||||||
|
// アンテナ作成者がノート作成者にブロックされていたらスキップ
|
||||||
|
const blockings = await blockingCache.fetch(noteUser.id, () => Blockings.find({ blockerId: noteUser.id }).then(res => res.map(x => x.blockeeId)));
|
||||||
|
if (blockings.some(blocking => blocking === antenna.userId)) return false;
|
||||||
|
|
||||||
if (note.visibility === 'followers') {
|
if (note.visibility === 'followers') {
|
||||||
if (noteUserFollowers && !noteUserFollowers.includes(antenna.userId)) return false;
|
if (noteUserFollowers && !noteUserFollowers.includes(antenna.userId)) return false;
|
||||||
if (antennaUserFollowing && !antennaUserFollowing.includes(note.userId)) return false;
|
if (antennaUserFollowing && !antennaUserFollowing.includes(note.userId)) return false;
|
||||||
|
|
|
@ -275,22 +275,13 @@ export default async (user: { id: User['id']; username: User['username']; host:
|
||||||
});
|
});
|
||||||
|
|
||||||
// Antenna
|
// Antenna
|
||||||
// TODO: キャッシュしたい
|
for (const antenna of (await getAntennas())) {
|
||||||
Followings.createQueryBuilder('following')
|
checkHitAntenna(antenna, note, user).then(hit => {
|
||||||
.andWhere(`following.followeeId = :userId`, { userId: note.userId })
|
if (hit) {
|
||||||
.getMany()
|
addNoteToAntenna(antenna, note, user);
|
||||||
.then(async followings => {
|
|
||||||
const blockings = await Blockings.find({ blockerId: user.id });
|
|
||||||
const followers = followings.map(f => f.followerId);
|
|
||||||
for (const antenna of (await getAntennas())) {
|
|
||||||
if (blockings.some(blocking => blocking.blockeeId === antenna.userId)) continue; // この処理は checkHitAntenna 内でやるようにしてもいいかも
|
|
||||||
checkHitAntenna(antenna, note, user, followers).then(hit => {
|
|
||||||
if (hit) {
|
|
||||||
addNoteToAntenna(antenna, note, user);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Channel
|
// Channel
|
||||||
if (note.channelId) {
|
if (note.channelId) {
|
||||||
|
|
|
@ -7,10 +7,10 @@
|
||||||
<MkSelect v-model="src" class="_formBlock">
|
<MkSelect v-model="src" class="_formBlock">
|
||||||
<template #label>{{ $ts.antennaSource }}</template>
|
<template #label>{{ $ts.antennaSource }}</template>
|
||||||
<option value="all">{{ $ts._antennaSources.all }}</option>
|
<option value="all">{{ $ts._antennaSources.all }}</option>
|
||||||
<option value="home">{{ $ts._antennaSources.homeTimeline }}</option>
|
<!--<option value="home">{{ $ts._antennaSources.homeTimeline }}</option>-->
|
||||||
<option value="users">{{ $ts._antennaSources.users }}</option>
|
<option value="users">{{ $ts._antennaSources.users }}</option>
|
||||||
<option value="list">{{ $ts._antennaSources.userList }}</option>
|
<!--<option value="list">{{ $ts._antennaSources.userList }}</option>-->
|
||||||
<option value="group">{{ $ts._antennaSources.userGroup }}</option>
|
<!--<option value="group">{{ $ts._antennaSources.userGroup }}</option>-->
|
||||||
</MkSelect>
|
</MkSelect>
|
||||||
<MkSelect v-if="src === 'list'" v-model="userListId" class="_formBlock">
|
<MkSelect v-if="src === 'list'" v-model="userListId" class="_formBlock">
|
||||||
<template #label>{{ $ts.userList }}</template>
|
<template #label>{{ $ts.userList }}</template>
|
||||||
|
|
Loading…
Reference in a new issue