server: remove elasticsearch
Changelog: Removed
This commit is contained in:
parent
35735342c1
commit
d87de46217
9 changed files with 29 additions and 196 deletions
|
@ -68,17 +68,6 @@ redis:
|
|||
#prefix: example-prefix
|
||||
#db: 1
|
||||
|
||||
# ┌─────────────────────────────┐
|
||||
#───┘ Elasticsearch configuration └─────────────────────────────
|
||||
|
||||
# Elasticsearch is optional.
|
||||
#elasticsearch:
|
||||
# host: localhost
|
||||
# port: 9200
|
||||
# ssl: false
|
||||
# user:
|
||||
# pass:
|
||||
|
||||
# ┌─────────────────────┐
|
||||
#───┘ Other configuration └─────────────────────────────────────
|
||||
|
||||
|
|
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -29,7 +29,6 @@ built
|
|||
/data
|
||||
/.cache-loader
|
||||
/db
|
||||
/elasticsearch
|
||||
npm-debug.log
|
||||
*.pem
|
||||
run.bat
|
||||
|
|
|
@ -15,7 +15,6 @@
|
|||
"@bull-board/api": "^4.3.1",
|
||||
"@bull-board/koa": "^4.3.1",
|
||||
"@discordapp/twemoji": "14.0.2",
|
||||
"@elastic/elasticsearch": "7.11.0",
|
||||
"@koa/cors": "3.1.0",
|
||||
"@koa/multer": "3.0.0",
|
||||
"@koa/router": "9.0.1",
|
||||
|
|
|
@ -24,14 +24,6 @@ export type Source = {
|
|||
db?: number;
|
||||
prefix?: string;
|
||||
};
|
||||
elasticsearch?: {
|
||||
host: string;
|
||||
port: number;
|
||||
ssl?: boolean;
|
||||
user?: string;
|
||||
pass?: string;
|
||||
index?: string;
|
||||
};
|
||||
|
||||
proxy?: string;
|
||||
proxySmtp?: string;
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
import * as elasticsearch from '@elastic/elasticsearch';
|
||||
import config from '@/config/index.js';
|
||||
|
||||
const index = {
|
||||
settings: {
|
||||
analysis: {
|
||||
analyzer: {
|
||||
ngram: {
|
||||
tokenizer: 'ngram',
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
mappings: {
|
||||
properties: {
|
||||
text: {
|
||||
type: 'text',
|
||||
index: true,
|
||||
analyzer: 'ngram',
|
||||
},
|
||||
userId: {
|
||||
type: 'keyword',
|
||||
index: true,
|
||||
},
|
||||
userHost: {
|
||||
type: 'keyword',
|
||||
index: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
// Init ElasticSearch connection
|
||||
const client = config.elasticsearch ? new elasticsearch.Client({
|
||||
node: `${config.elasticsearch.ssl ? 'https://' : 'http://'}${config.elasticsearch.host}:${config.elasticsearch.port}`,
|
||||
auth: (config.elasticsearch.user && config.elasticsearch.pass) ? {
|
||||
username: config.elasticsearch.user,
|
||||
password: config.elasticsearch.pass,
|
||||
} : undefined,
|
||||
pingTimeout: 30000,
|
||||
}) : null;
|
||||
|
||||
if (client) {
|
||||
client.indices.exists({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
}).then(exist => {
|
||||
if (!exist.body) {
|
||||
client.indices.create({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
body: index,
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
export default client;
|
|
@ -203,10 +203,6 @@ export const meta = {
|
|||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
elasticsearch: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
},
|
||||
hcaptcha: {
|
||||
type: 'boolean',
|
||||
optional: false, nullable: false,
|
||||
|
@ -319,7 +315,6 @@ export default define(meta, paramDef, async () => {
|
|||
localTimeLine: !instance.disableLocalTimeline,
|
||||
globalTimeLine: !instance.disableGlobalTimeline,
|
||||
emailRequiredForSignup: instance.emailRequiredForSignup,
|
||||
elasticsearch: config.elasticsearch ? true : false,
|
||||
hcaptcha: instance.enableHcaptcha,
|
||||
recaptcha: instance.enableRecaptcha,
|
||||
objectStorage: instance.useObjectStorage,
|
||||
|
|
|
@ -1,7 +1,4 @@
|
|||
import { In } from 'typeorm';
|
||||
import { Notes } from '@/models/index.js';
|
||||
import config from '@/config/index.js';
|
||||
import es from '@/db/elasticsearch.js';
|
||||
import define from '@/server/api/define.js';
|
||||
import { makePaginationQuery } from '@/server/api/common/make-pagination-query.js';
|
||||
import { visibilityQuery } from '@/server/api/common/generate-visibility-query.js';
|
||||
|
@ -45,96 +42,34 @@ export const paramDef = {
|
|||
|
||||
// eslint-disable-next-line import/no-default-export
|
||||
export default define(meta, paramDef, async (ps, me) => {
|
||||
if (es == null) {
|
||||
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId);
|
||||
const query = makePaginationQuery(Notes.createQueryBuilder('note'), ps.sinceId, ps.untilId);
|
||||
|
||||
if (ps.userId) {
|
||||
query.andWhere('note.userId = :userId', { userId: ps.userId });
|
||||
} else if (ps.host) {
|
||||
query.andWhere('note.userHost = :host', { host: ps.host });
|
||||
} else if (ps.channelId) {
|
||||
query.andWhere('note.channelId = :channelId', { channelId: ps.channelId });
|
||||
}
|
||||
|
||||
query
|
||||
.andWhere('note.text ILIKE :q', { q: `%${ps.query}%` })
|
||||
.innerJoinAndSelect('note.user', 'user')
|
||||
.leftJoinAndSelect('user.avatar', 'avatar')
|
||||
.leftJoinAndSelect('user.banner', 'banner')
|
||||
.leftJoinAndSelect('note.reply', 'reply')
|
||||
.leftJoinAndSelect('note.renote', 'renote')
|
||||
.leftJoinAndSelect('reply.user', 'replyUser')
|
||||
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
||||
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
||||
.leftJoinAndSelect('renote.user', 'renoteUser')
|
||||
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
||||
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
||||
|
||||
if (me) generateMutedUserQuery(query, me);
|
||||
if (me) generateBlockedUserQuery(query, me);
|
||||
|
||||
const notes = await visibilityQuery(query, me).take(ps.limit).getMany();
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
} else {
|
||||
const userQuery = ps.userId != null ? [{
|
||||
term: {
|
||||
userId: ps.userId,
|
||||
},
|
||||
}] : [];
|
||||
|
||||
const hostQuery = ps.userId == null ?
|
||||
ps.host === null ? [{
|
||||
bool: {
|
||||
must_not: {
|
||||
exists: {
|
||||
field: 'userHost',
|
||||
},
|
||||
},
|
||||
},
|
||||
}] : ps.host !== undefined ? [{
|
||||
term: {
|
||||
userHost: ps.host,
|
||||
},
|
||||
}] : []
|
||||
: [];
|
||||
|
||||
const result = await es.search({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
body: {
|
||||
size: ps.limit,
|
||||
from: ps.offset,
|
||||
query: {
|
||||
bool: {
|
||||
must: [{
|
||||
simple_query_string: {
|
||||
fields: ['text'],
|
||||
query: ps.query.toLowerCase(),
|
||||
default_operator: 'and',
|
||||
},
|
||||
}, ...hostQuery, ...userQuery],
|
||||
},
|
||||
},
|
||||
sort: [{
|
||||
_doc: 'desc',
|
||||
}],
|
||||
},
|
||||
});
|
||||
|
||||
const hits = result.body.hits.hits.map((hit: any) => hit._id);
|
||||
|
||||
if (hits.length === 0) return [];
|
||||
|
||||
// Fetch found notes
|
||||
const notes = await Notes.find({
|
||||
where: {
|
||||
id: In(hits),
|
||||
},
|
||||
order: {
|
||||
id: -1,
|
||||
},
|
||||
});
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
if (ps.userId) {
|
||||
query.andWhere('note.userId = :userId', { userId: ps.userId });
|
||||
} else if (ps.host) {
|
||||
query.andWhere('note.userHost = :host', { host: ps.host });
|
||||
} else if (ps.channelId) {
|
||||
query.andWhere('note.channelId = :channelId', { channelId: ps.channelId });
|
||||
}
|
||||
|
||||
query
|
||||
.andWhere('note.text ILIKE :q', { q: `%${ps.query}%` })
|
||||
.innerJoinAndSelect('note.user', 'user')
|
||||
.leftJoinAndSelect('user.avatar', 'avatar')
|
||||
.leftJoinAndSelect('user.banner', 'banner')
|
||||
.leftJoinAndSelect('note.reply', 'reply')
|
||||
.leftJoinAndSelect('note.renote', 'renote')
|
||||
.leftJoinAndSelect('reply.user', 'replyUser')
|
||||
.leftJoinAndSelect('replyUser.avatar', 'replyUserAvatar')
|
||||
.leftJoinAndSelect('replyUser.banner', 'replyUserBanner')
|
||||
.leftJoinAndSelect('renote.user', 'renoteUser')
|
||||
.leftJoinAndSelect('renoteUser.avatar', 'renoteUserAvatar')
|
||||
.leftJoinAndSelect('renoteUser.banner', 'renoteUserBanner');
|
||||
|
||||
if (me) generateMutedUserQuery(query, me);
|
||||
if (me) generateBlockedUserQuery(query, me);
|
||||
|
||||
const notes = await visibilityQuery(query, me).take(ps.limit).getMany();
|
||||
|
||||
return await Notes.packMany(notes, me);
|
||||
});
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
import es from '@/db/elasticsearch.js';
|
||||
import config from '@/config/index.js';
|
||||
import { Note } from '@/models/entities/note.js';
|
||||
import { UserProfiles } from '@/models/index.js';
|
||||
import { normalizeForSearch } from '@/misc/normalize-for-search.js';
|
||||
import { Cache } from '@/misc/cache.js';
|
||||
import { UserProfile } from '@/models/entities/user-profile.js';
|
||||
import { MINUTE } from '@/const.js';
|
||||
|
@ -16,17 +13,3 @@ export const mutedWordsCache = new Cache<{ userId: UserProfile['userId']; mutedW
|
|||
select: ['userId', 'mutedWords'],
|
||||
}),
|
||||
);
|
||||
|
||||
export function index(note: Note): void {
|
||||
if (note.text == null || config.elasticsearch == null) return;
|
||||
|
||||
es.index({
|
||||
index: config.elasticsearch.index || 'misskey_note',
|
||||
id: note.id.toString(),
|
||||
body: {
|
||||
text: normalizeForSearch(note.text),
|
||||
userId: note.userId,
|
||||
userHost: note.userHost,
|
||||
},
|
||||
});
|
||||
}
|
||||
|
|
|
@ -26,7 +26,7 @@ import { registerOrFetchInstanceDoc } from '../register-or-fetch-instance-doc.js
|
|||
import { createNotification } from '../create-notification.js';
|
||||
import { addNoteToAntenna } from '../add-note-to-antenna.js';
|
||||
import { deliverToRelays } from '../relay.js';
|
||||
import { mutedWordsCache, index } from './index.js';
|
||||
import { mutedWordsCache } from './index.js';
|
||||
import { Polls } from '@/models/index.js';
|
||||
import { Poll } from '@/models/entities/poll.js';
|
||||
|
||||
|
@ -399,9 +399,6 @@ export async function sideEffects(user: User, note: Note, silent = false, create
|
|||
|
||||
// TODO AP deliver
|
||||
}
|
||||
|
||||
// Register to search database
|
||||
index(note);
|
||||
}
|
||||
|
||||
async function notifyWatchers(noteId: Note['id'], user: { id: User['id']; }, nm: NotificationManager, type: NotificationType): Promise<void> {
|
||||
|
|
Loading…
Reference in a new issue