mirror of https://github.com/halo-dev/halo
![]() #### What type of PR is this? /kind improvement /area core /milestone 2.17.x #### What this PR does / why we need it: 重构索引机制的查询和排序以提升整体性能 **how to test it?** 使用 postgre 数据库,初始化 Halo ,然后执行以下脚本创建 30w 文章数据进行测试: <details> <summary>点击展开查看 SQL</summary> ```sql DO $$ DECLARE i integer; postNameIndex integer; snapshotName varchar; totalRecords integer; BEGIN postNameIndex := 1; totalRecords := 300000; FOR i IN 1..3 LOOP INSERT INTO "public"."extensions" ("name", "data", "version") VALUES ( '/registry/content.halo.run/categories/category-'||i, convert_to( jsonb_build_object( 'spec', jsonb_build_object( 'displayName', '分类-'||i, 'slug', 'category-'||i, 'description', '测试分类', 'cover', '', 'template', '', 'priority', 0, 'children', '[]'::jsonb ), 'status', jsonb_build_object( 'permalink', '/categories/category-'||i, 'postCount', totalRecords, 'visiblePostCount', totalRecords ), 'apiVersion', 'content.halo.run/v1alpha1', 'kind', 'Category', 'metadata', jsonb_build_object( 'finalizers', jsonb_build_array('category-protection'), 'name', 'category-' || i, 'annotations', jsonb_build_object( 'content.halo.run/permalink-pattern', 'categories' ), 'version', 0, 'creationTimestamp', '2024-06-12T03:56:40.315592Z' ) )::text, 'UTF8'), 0 ); END LOOP; FOR i IN 1..3 LOOP INSERT INTO "public"."extensions" ("name", "data", "version") VALUES ( '/registry/content.halo.run/tags/tag-' || i, convert_to( jsonb_build_object( 'spec', jsonb_build_object( 'displayName', 'Halo tag ' || i, 'slug', 'tag-'||i, 'color', '#ffffff', 'cover', '' ), 'status', jsonb_build_object( 'permalink', '/tags/tag-' || i, 'visiblePostCount', totalRecords, 'postCount', totalRecords, 'observedVersion', 0 ), 'apiVersion', 'content.halo.run/v1alpha1', 'kind', 'Tag', 'metadata', jsonb_build_object( 'finalizers', jsonb_build_array('tag-protection'), 'name', 'tag-'||i, 'annotations', jsonb_build_object( 'content.halo.run/permalink-pattern', 'tags' ), 'version', 0, 'creationTimestamp', '2024-06-12T03:56:40.406407Z' ) )::text, 'UTF8'), 0); END LOOP; FOR i IN postNameIndex..totalRecords LOOP -- Generate snapshotName snapshotName := 'snapshot-' || i; -- Insert post data INSERT INTO "public"."extensions" ("name", "data", "version") VALUES ( '/registry/content.halo.run/posts/post-' || postNameIndex, convert_to( jsonb_build_object( 'spec', jsonb_build_object( 'title', 'title-' || postNameIndex, 'slug', 'slug-' || postNameIndex, 'releaseSnapshot', snapshotName, 'headSnapshot', snapshotName, 'baseSnapshot', snapshotName, 'owner', 'admin', 'template', '', 'cover', '', 'deleted', false, 'publish', true, 'pinned', false, 'allowComment', true, 'visible', 'PUBLIC', 'priority', 0, 'excerpt', jsonb_build_object( 'autoGenerate', true, 'raw', '' ), 'categories', ARRAY['category-kEvDb', 'category-XcRVk', 'category-adca'], 'tags', ARRAY['tag-RtKos', 'tag-vEsTR', 'tag-UBKCc'], 'htmlMetas', '[]'::jsonb ), 'status', jsonb_build_object( 'phase', 'PUBLISHED', 'conditions', ARRAY[ jsonb_build_object( 'type', 'PUBLISHED', 'status', 'TRUE', 'lastTransitionTime', '2024-06-11T10:16:15.617748Z', 'message', 'Post published successfully.', 'reason', 'Published' ), jsonb_build_object( 'type', 'DRAFT', 'status', 'TRUE', 'lastTransitionTime', '2024-06-11T10:16:15.457668Z', 'message', 'Drafted post successfully.', 'reason', 'DraftedSuccessfully' ) ], 'permalink', '/archives/slug-' || postNameIndex, 'excerpt', '如果你看到了这一篇文章,那么证明你已经安装成功了,感谢使用 Halo 进行创作,希望能够使用愉快。', 'inProgress', false, 'contributors', ARRAY['admin'], 'lastModifyTime', '2024-06-11T10:16:15.421467Z', 'observedVersion', 0 ), 'apiVersion', 'content.halo.run/v1alpha1', 'kind', 'Post', 'metadata', jsonb_build_object( 'finalizers', ARRAY['post-protection'], 'name', 'post-' || postNameIndex, 'labels', jsonb_build_object( 'content.halo.run/published', 'true', 'content.halo.run/deleted', 'false', 'content.halo.run/owner', 'admin', 'content.halo.run/visible', 'PUBLIC', 'content.halo.run/archive-year', '2024', 'content.halo.run/archive-month', '06', 'content.halo.run/archive-day', '11' ), 'annotations', jsonb_build_object( 'content.halo.run/permalink-pattern', '/archives/{slug}', 'content.halo.run/last-released-snapshot', snapshotName, 'checksum/config', '73e40d4115f5a7d1e74fcc9228861c53d2ef60468e1e606e367b01efef339309' ), 'version', 0, 'creationTimestamp', '2024-06-11T05:51:46.059292Z' ) )::text, 'UTF8'), 1 ); -- Insert content data INSERT INTO "public"."extensions" ("name", "data", "version") VALUES ( '/registry/content.halo.run/snapshots/' || snapshotName, convert_to( jsonb_build_object( 'spec', jsonb_build_object( 'subjectRef', jsonb_build_object( 'group', 'content.halo.run', 'version', 'v1alpha1', 'kind', 'Post', 'name', 'post-' || postNameIndex ), 'rawType', 'HTML', 'rawPatch', '<p style=\"\">测试内容</p>', 'contentPatch', '<p style=\"\">测试内容</p>', 'lastModifyTime', '2024-06-11T06:01:25.748755Z', 'owner', 'admin', 'contributors', ARRAY['admin'] ), 'apiVersion', 'content.halo.run/v1alpha1', 'kind', 'Snapshot', 'metadata', jsonb_build_object( 'name', snapshotName, 'annotations', jsonb_build_object( 'content.halo.run/keep-raw', 'true' ), 'creationTimestamp', '2024-06-11T06:01:25.748925Z' ) )::text, 'UTF8'), 1 ); postNameIndex := postNameIndex + 1; END LOOP; END $$; ``` </details> 使用以下 API 查询文章 ``` curl 'http://localhost:8090/apis/api.console.halo.run/v1alpha1/posts?page=1&size=20&labelSelector=content.halo.run%2Fdeleted%3Dfalse&labelSelector=content.halo.run%2Fpublished%3Dtrue&fieldSelector=spec.categories%3Dcategory-1&fieldSelector=spec.tags%3Dc33ceabb-d8f1-4711-8991-bb8f5c92ad7c&fieldSelector=status.contributors%3Dadmin&fieldSelector=spec.visible%3DPUBLIC' \ --header 'Authorization: Basic YWRtaW46YWRtaW4=' ``` Before:  After:  #### Does this PR introduce a user-facing change? ```release-note 重构索引机制的查询和排序使整体性能提升 50% 以上 ``` |
||
---|---|---|
.github | ||
api | ||
api-docs/openapi/v3_0 | ||
application | ||
buildSrc | ||
config/checkstyle | ||
docs | ||
e2e | ||
gradle/wrapper | ||
hack | ||
platform | ||
ui | ||
.dockerignore | ||
.editorconfig | ||
.gitattributes | ||
.gitignore | ||
.gitpod.yml | ||
CODE_OF_CONDUCT.md | ||
CONTRIBUTING.md | ||
Dockerfile | ||
LICENSE | ||
OWNERS | ||
README.md | ||
SECURITY.md | ||
build.gradle | ||
gradle.properties | ||
gradlew | ||
gradlew.bat | ||
settings.gradle |
README.md
Halo [ˈheɪloʊ],强大易用的开源建站工具。
快速开始
docker run -d --name halo -p 8090:8090 -v ~/.halo2:/root/.halo2 halohub/halo:2.16
以上仅作为体验使用,详细部署文档请查阅:https://docs.halo.run/getting-started/install/docker-compose
在线体验
- 环境地址:https://demo.halo.run
- 后台地址:https://demo.halo.run/console
- 用户名:
demo
- 密码:
P@ssw0rd123..
生态
可访问 官方应用市场 或 awesome-halo 仓库 查看适用于 Halo 2.x 的主题和插件。
许可证
Halo 使用 GPL-v3.0 协议开源,请遵守开源协议。
赞助
如果 Halo 对你有帮助,欢迎赞助我们,感谢以下赞助者对 Halo 项目的支持:
贡献
参考 CONTRIBUTING。