mirror of
https://github.com/mattermost/focalboard.git
synced 2025-03-26 20:53:55 +02:00
Updates db indexes to improve performance (#3732)
* Updates db indexes to improve performance * Fix order-dependant test * Fix another order-dependant test
This commit is contained in:
parent
99c854ab2c
commit
03a6a963eb
server/services/store
@ -0,0 +1,39 @@
|
||||
DROP INDEX idx_subscriptions_subscriber_id ON {{.prefix}}subscriptions;
|
||||
DROP INDEX idx_blocks_board_id_parent_id ON {{.prefix}}blocks;
|
||||
|
||||
{{if .mysql}}
|
||||
ALTER TABLE {{.prefix}}blocks DROP PRIMARY KEY;
|
||||
ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (channel_id, id);
|
||||
{{end}}
|
||||
|
||||
{{if .postgres}}
|
||||
ALTER TABLE {{.prefix}}blocks DROP CONSTRAINT {{.prefix}}blocks_pkey1;
|
||||
ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (channel_id, id);
|
||||
{{end}}
|
||||
|
||||
{{if .sqlite}}
|
||||
ALTER TABLE {{.prefix}}blocks RENAME TO {{.prefix}}blocks_tmp;
|
||||
|
||||
CREATE TABLE {{.prefix}}blocks (
|
||||
id VARCHAR(36),
|
||||
insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
|
||||
parent_id VARCHAR(36),
|
||||
schema BIGINT,
|
||||
type TEXT,
|
||||
title TEXT,
|
||||
fields TEXT,
|
||||
create_at BIGINT,
|
||||
update_at BIGINT,
|
||||
delete_at BIGINT,
|
||||
root_id VARCHAR(36),
|
||||
modified_by VARCHAR(36),
|
||||
channel_id VARCHAR(36),
|
||||
created_by VARCHAR(36),
|
||||
board_id VARCHAR(36),
|
||||
PRIMARY KEY (channel_id, id)
|
||||
);
|
||||
|
||||
INSERT INTO {{.prefix}}blocks SELECT * FROM {{.prefix}}blocks_tmp;
|
||||
|
||||
DROP TABLE {{.prefix}}blocks_tmp;
|
||||
{{end}}
|
@ -0,0 +1,44 @@
|
||||
{{- /* delete old blocks PK and add id as the new one */ -}}
|
||||
{{if .mysql}}
|
||||
ALTER TABLE {{.prefix}}blocks DROP PRIMARY KEY;
|
||||
ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (id);
|
||||
{{end}}
|
||||
|
||||
{{if .postgres}}
|
||||
ALTER TABLE {{.prefix}}blocks DROP CONSTRAINT {{.prefix}}blocks_pkey1;
|
||||
ALTER TABLE {{.prefix}}blocks ADD PRIMARY KEY (id);
|
||||
{{end}}
|
||||
|
||||
{{- /* there is no way for SQLite to update the PK or add a unique constraint */ -}}
|
||||
{{if .sqlite}}
|
||||
ALTER TABLE {{.prefix}}blocks RENAME TO {{.prefix}}blocks_tmp;
|
||||
|
||||
CREATE TABLE {{.prefix}}blocks (
|
||||
id VARCHAR(36),
|
||||
insert_at DATETIME NOT NULL DEFAULT(STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')),
|
||||
parent_id VARCHAR(36),
|
||||
schema BIGINT,
|
||||
type TEXT,
|
||||
title TEXT,
|
||||
fields TEXT,
|
||||
create_at BIGINT,
|
||||
update_at BIGINT,
|
||||
delete_at BIGINT,
|
||||
root_id VARCHAR(36),
|
||||
modified_by VARCHAR(36),
|
||||
channel_id VARCHAR(36),
|
||||
created_by VARCHAR(36),
|
||||
board_id VARCHAR(36),
|
||||
PRIMARY KEY (id)
|
||||
);
|
||||
|
||||
INSERT INTO {{.prefix}}blocks SELECT * FROM {{.prefix}}blocks_tmp;
|
||||
|
||||
DROP TABLE {{.prefix}}blocks_tmp;
|
||||
{{end}}
|
||||
|
||||
{{- /* most block searches use board_id or a combination of board and parent ids */ -}}
|
||||
CREATE INDEX idx_blocks_board_id_parent_id ON {{.prefix}}blocks (board_id, parent_id);
|
||||
|
||||
{{- /* get subscriptions is used once per board page load */ -}}
|
||||
CREATE INDEX idx_subscriptions_subscriber_id ON {{.prefix}}subscriptions (subscriber_id);
|
@ -952,12 +952,12 @@ func testGetBlockMetadata(t *testing.T, store store.Store) {
|
||||
})
|
||||
|
||||
t.Run("get block history after updateAt", func(t *testing.T) {
|
||||
rBlocks, err2 := store.GetBlocksWithType(boardID, "test")
|
||||
rBlock, err2 := store.GetBlock("block3")
|
||||
require.NoError(t, err2)
|
||||
require.NotZero(t, rBlocks[2].UpdateAt)
|
||||
require.NotZero(t, rBlock.UpdateAt)
|
||||
|
||||
opts := model.QueryBlockHistoryOptions{
|
||||
AfterUpdateAt: rBlocks[2].UpdateAt,
|
||||
AfterUpdateAt: rBlock.UpdateAt,
|
||||
Descending: false,
|
||||
}
|
||||
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
||||
@ -970,12 +970,12 @@ func testGetBlockMetadata(t *testing.T, store store.Store) {
|
||||
})
|
||||
|
||||
t.Run("get block history before updateAt", func(t *testing.T) {
|
||||
rBlocks, err2 := store.GetBlocksWithType(boardID, "test")
|
||||
rBlock, err2 := store.GetBlock("block3")
|
||||
require.NoError(t, err2)
|
||||
require.NotZero(t, rBlocks[2].UpdateAt)
|
||||
require.NotZero(t, rBlock.UpdateAt)
|
||||
|
||||
opts := model.QueryBlockHistoryOptions{
|
||||
BeforeUpdateAt: rBlocks[2].UpdateAt,
|
||||
BeforeUpdateAt: rBlock.UpdateAt,
|
||||
Descending: true,
|
||||
}
|
||||
blocks, err = store.GetBlockHistoryDescendants(boardID, opts)
|
||||
|
Loading…
x
Reference in New Issue
Block a user