generated from halo-dev/plugin-starter
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: using indexes to optimize queries (#69)
### What this PR does? 使用索引来优化瞬间查询 **how to test it?** 基于 Halo 2.12.0 可以使用以下 jar 包测试(keyword 查询目前没有对内容建索引,暂时只可以根据 owner 用户名查询): [plugin-moments-1.0.1-SNAPSHOT.jar.zip](https://github.com/halo-sigs/plugin-moments/files/14061573/plugin-moments-1.0.1-SNAPSHOT.jar.zip) 可以使用 postgre 数据库用以下脚本插入数据测试: <details> <summary>点击展开查看 SQL</summary> ```sql CREATE OR REPLACE FUNCTION random_string(length integer) RETURNS text AS $$ DECLARE chars text[] := array ['a','b','c','d','e','f','g','h','i','j','k','l','m', 'n','o','p','q','r','s','t','u','v','w','x','y','z', 'A','B','C','D','E','F','G','H','I','J','K','L','M', 'N','O','P','Q','R','S','T','U','V','W','X','Y','Z', '0','1','2','3','4','5','6','7','8','9']; result text := ''; i integer := 0; BEGIN FOR i IN 1..length LOOP result := result || chars[1 + floor(random() * array_length(chars, 1))]; END LOOP; RETURN result; END; $$ LANGUAGE plpgsql; DO $$ DECLARE json_data jsonb; bytea_data bytea; i integer; BEGIN -- 可以修改此处的值来创建更大的数据集,默认 1w FOR i IN 1..10000 LOOP -- 创建初始 JSON 数据 json_data := '{ "spec": { "content": { "raw": "", "medium": [] }, "releaseTime": "2024-01-09T07:24:46.077Z", "visible": "PUBLIC", "owner": "admin", "tags": [] }, "status": { "observedVersion": 0 }, "apiVersion": "moment.halo.run/v1alpha1", "kind": "Moment", "metadata": { "finalizers": [ "moment-protection" ], "name": "", "version": 0, "creationTimestamp": "2024-01-09T07:33:56.172968174Z" } }'::jsonb; -- 更新 'raw' 字段 json_data := jsonb_set(json_data, '{spec, content, raw}', to_jsonb('<p>' || random_string(20000) || '</p>'), TRUE); json_data := jsonb_set(json_data, '{spec, content, html}', to_jsonb('<p>' || random_string(20000) || '</p>'), TRUE); -- 更新 'metadata.name' 字段 json_data := jsonb_set(json_data, '{metadata, name}', to_jsonb('moment-' || i), TRUE); -- 将 JSON 数据转换为 bytea bytea_data := convert_to(json_data::text, 'UTF8'); -- 插入数据 INSERT INTO extensions (name, data, version) VALUES ('/registry/moment.halo.run/moments/moment-' || i, bytea_data, 0); END LOOP; END $$; ``` </details> ```release-note 适配索引功能来优化瞬间的查询请求以提高响应速度并降低内存占用 ```
- Loading branch information
Showing
15 changed files
with
232 additions
and
483 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.