/
githubmirror
/
hexo
Обзор
Документация
Войти
/
githubmirror
/
hexo
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
lib/models/post_category.ts
27 строк
741 B
D-Sketon
perf(PostCategory/PostTag): add binary relation index for performance (#5605)
06 фев 2025, 12:54
Не верифицирован
06 фев 2025, 12:54
4362bf4
Код
Авторство
О чём код?
import warehouse from 'warehouse'; import type Hexo from '../hexo'; import { PostCategorySchema } from '../types'; export = (ctx: Hexo) => { const PostCategory = new warehouse.Schema<PostCategorySchema>({ post_id: {type: warehouse.Schema.Types.CUID, ref: 'Post'}, category_id: {type: warehouse.Schema.Types.CUID, ref: 'Category'} }); PostCategory.pre('save', data => { ctx._binaryRelationIndex.post_category.removeHook(data); return data; }); PostCategory.post('save', data => { ctx._binaryRelationIndex.post_category.saveHook(data); return data; }); PostCategory.pre('remove', data => { ctx._binaryRelationIndex.post_category.removeHook(data); return data; }); return PostCategory; };