Add index on seen & hide long messages

This commit does two things:
1) Add an index on seen & update only the not-seen messages in the query
2) Hide long messages in the database, as that's likely spam
This commit is contained in:
Andrea Maria Piana 2020-09-10 08:57:45 +02:00
parent e836ffb47f
commit 61b345ff33
5 changed files with 58 additions and 6 deletions

View File

@ -1 +1 @@
0.61.0
0.61.1

View File

@ -654,7 +654,7 @@ func (db sqlitePersistence) MarkAllRead(chatID string) error {
_ = tx.Rollback()
}()
_, err = tx.Exec(`UPDATE user_messages SET seen = 1 WHERE local_chat_id = ?`, chatID)
_, err = tx.Exec(`UPDATE user_messages SET seen = 1 WHERE local_chat_id = ? AND seen != 1`, chatID)
if err != nil {
return err
}

View File

@ -26,6 +26,8 @@
// 1598955122_add_mentions.up.sql (52B)
// 1599641390_add_emoji_reactions_index.down.sql (67B)
// 1599641390_add_emoji_reactions_index.up.sql (126B)
// 1599720851_add_seen_index_remove_long_messages.down.sql (96B)
// 1599720851_add_seen_index_remove_long_messages.up.sql (136B)
// doc.go (850B)
package migrations
@ -550,7 +552,7 @@ func _1598955122_add_mentionsDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1598955122_add_mentions.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1599679300, 0)}
info := bindataFileInfo{name: "1598955122_add_mentions.down.sql", size: 0, mode: os.FileMode(0644), modTime: time.Unix(1599682300, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe3, 0xb0, 0xc4, 0x42, 0x98, 0xfc, 0x1c, 0x14, 0x9a, 0xfb, 0xf4, 0xc8, 0x99, 0x6f, 0xb9, 0x24, 0x27, 0xae, 0x41, 0xe4, 0x64, 0x9b, 0x93, 0x4c, 0xa4, 0x95, 0x99, 0x1b, 0x78, 0x52, 0xb8, 0x55}}
return a, nil
}
@ -570,7 +572,7 @@ func _1598955122_add_mentionsUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1598955122_add_mentions.up.sql", size: 52, mode: os.FileMode(0644), modTime: time.Unix(1599679300, 0)}
info := bindataFileInfo{name: "1598955122_add_mentions.up.sql", size: 52, mode: os.FileMode(0644), modTime: time.Unix(1599682300, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x8d, 0x22, 0x17, 0x92, 0xd2, 0x11, 0x4e, 0x7, 0x93, 0x9a, 0x55, 0xfd, 0xb, 0x97, 0xc4, 0x63, 0x6a, 0x81, 0x97, 0xcd, 0xb2, 0xf8, 0x4b, 0x5f, 0x3c, 0xfa, 0x3a, 0x38, 0x53, 0x10, 0xed, 0x9d}}
return a, nil
}
@ -590,7 +592,7 @@ func _1599641390_add_emoji_reactions_indexDownSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1599641390_add_emoji_reactions_index.down.sql", size: 67, mode: os.FileMode(0644), modTime: time.Unix(1599679300, 0)}
info := bindataFileInfo{name: "1599641390_add_emoji_reactions_index.down.sql", size: 67, mode: os.FileMode(0644), modTime: time.Unix(1599682300, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x89, 0x39, 0x0, 0x51, 0x5b, 0x48, 0xc3, 0xf3, 0x6a, 0x96, 0xf1, 0xd2, 0xa6, 0x60, 0xa8, 0x68, 0x21, 0xb5, 0xa0, 0x11, 0x11, 0x99, 0xde, 0xad, 0xa6, 0xa7, 0x56, 0xc1, 0xb2, 0xa6, 0x63, 0xe4}}
return a, nil
}
@ -610,11 +612,51 @@ func _1599641390_add_emoji_reactions_indexUpSql() (*asset, error) {
return nil, err
}
info := bindataFileInfo{name: "1599641390_add_emoji_reactions_index.up.sql", size: 126, mode: os.FileMode(0644), modTime: time.Unix(1599679300, 0)}
info := bindataFileInfo{name: "1599641390_add_emoji_reactions_index.up.sql", size: 126, mode: os.FileMode(0644), modTime: time.Unix(1599682300, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xf9, 0xd8, 0xdc, 0xa7, 0xb, 0x92, 0x7a, 0x61, 0x37, 0x24, 0x1c, 0x77, 0x5e, 0xe, 0x7e, 0xfc, 0x9f, 0x98, 0x7b, 0x65, 0xe7, 0xf9, 0x71, 0x57, 0x89, 0x2d, 0x90, 0x1b, 0xf6, 0x5e, 0x37, 0xe8}}
return a, nil
}
var __1599720851_add_seen_index_remove_long_messagesDownSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x09\xf2\x0f\x50\xf0\xf4\x73\x71\x8d\x50\x28\x4e\x4d\xcd\x8b\xcf\xc9\x4f\x4e\xcc\x89\x4f\xce\x48\x2c\x89\xcf\x4c\x89\xcf\x4c\xa9\xb0\xe6\x0a\x0d\x70\x71\x0c\x71\x55\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\x56\x08\x76\x0d\x51\xc8\xc8\x4c\x49\x55\xb0\x55\x30\x50\x08\xf7\x70\x0d\x72\x55\xc8\x49\xcd\x4b\x2f\xc9\xd0\x28\x49\xad\x28\xd1\x54\xb0\x53\x30\x31\xb0\x34\xb3\xe6\x02\x04\x00\x00\xff\xff\x51\x4e\x52\x39\x60\x00\x00\x00")
func _1599720851_add_seen_index_remove_long_messagesDownSqlBytes() ([]byte, error) {
return bindataRead(
__1599720851_add_seen_index_remove_long_messagesDownSql,
"1599720851_add_seen_index_remove_long_messages.down.sql",
)
}
func _1599720851_add_seen_index_remove_long_messagesDownSql() (*asset, error) {
bytes, err := _1599720851_add_seen_index_remove_long_messagesDownSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "1599720851_add_seen_index_remove_long_messages.down.sql", size: 96, mode: os.FileMode(0644), modTime: time.Unix(1599720983, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0x6f, 0x80, 0x18, 0xaf, 0xf9, 0x83, 0xd6, 0xcb, 0xa1, 0xc1, 0xf1, 0xf6, 0x32, 0x11, 0xd2, 0x72, 0xef, 0x74, 0x83, 0x53, 0x3a, 0xc4, 0x77, 0x6, 0x66, 0xa0, 0xe3, 0x5a, 0x4d, 0x1b, 0x30, 0x6}}
return a, nil
}
var __1599720851_add_seen_index_remove_long_messagesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x72\x0e\x72\x75\x0c\x71\x55\xf0\xf4\x73\x71\x8d\x50\x28\x4e\x4d\xcd\x8b\xcf\xc9\x4f\x4e\xcc\x89\x4f\xce\x48\x2c\x89\xcf\x4c\x89\xcf\x4c\xa9\x50\xf0\xf7\x53\x28\x2d\x4e\x2d\x8a\xcf\x4d\x2d\x2e\x4e\x4c\x4f\x2d\xd6\x40\x51\xa2\x03\xd6\xa6\x69\xcd\x15\x1a\xe0\x02\x32\x0a\x45\xa9\x42\xb0\x6b\x88\x42\x46\x66\x4a\xaa\x82\xad\x82\xa1\x42\xb8\x87\x6b\x90\xab\x42\x4e\x6a\x5e\x7a\x49\x86\x46\x49\x6a\x45\x89\xa6\x82\x9d\x82\x89\x81\xa5\x99\x35\x17\x20\x00\x00\xff\xff\x17\x21\xe3\x82\x88\x00\x00\x00")
func _1599720851_add_seen_index_remove_long_messagesUpSqlBytes() ([]byte, error) {
return bindataRead(
__1599720851_add_seen_index_remove_long_messagesUpSql,
"1599720851_add_seen_index_remove_long_messages.up.sql",
)
}
func _1599720851_add_seen_index_remove_long_messagesUpSql() (*asset, error) {
bytes, err := _1599720851_add_seen_index_remove_long_messagesUpSqlBytes()
if err != nil {
return nil, err
}
info := bindataFileInfo{name: "1599720851_add_seen_index_remove_long_messages.up.sql", size: 136, mode: os.FileMode(0644), modTime: time.Unix(1599720954, 0)}
a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xe2, 0x5d, 0xc6, 0x4f, 0xc8, 0x1e, 0x11, 0x83, 0xa1, 0x7f, 0x63, 0xf0, 0x78, 0xb2, 0xa1, 0x8f, 0x16, 0x91, 0xd9, 0xbc, 0x55, 0xee, 0xde, 0xe5, 0x84, 0xff, 0xba, 0xec, 0x64, 0x15, 0x11, 0x6a}}
return a, nil
}
var _docGo = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x84\x52\x3f\x8f\xdb\x3e\x0c\xdd\xf3\x29\x1e\x6e\xb9\xe5\x22\x07\xf8\xfd\xa6\xdb\x3a\x74\xe8\xd2\x2e\xd9\x0b\x46\xa6\x6d\x22\x32\xe5\x8a\xf4\x39\xf9\xf6\x85\x74\x17\x9c\x51\x14\xe8\x4a\x89\x8f\xef\x5f\xd7\xe1\x3c\x89\x61\x90\xc4\x10\x83\x72\x64\x33\x2a\x77\x5c\x38\xd2\x6a\x8c\xa7\x51\x7c\x5a\x2f\x21\xe6\xb9\x33\x27\x5f\xed\x28\x73\x37\xcb\x58\xc8\xb9\x7b\xfb\xff\xe9\xd0\x75\x88\xa4\xcf\x8e\x89\xb4\x4f\xdc\xb0\x0c\xe6\x54\x5c\x74\xc4\x26\x3e\x81\xb0\x14\x1e\xe4\x16\xf0\xc5\x91\x98\xcc\xe1\x13\xf9\xb3\xc1\x27\x46\x24\xe3\x0a\x33\xe4\x82\x31\x1f\x2f\xa2\x3d\x39\x85\x3a\xfa\x36\xec\x26\x95\x61\xa4\x94\xb8\xc7\x50\xf2\xdc\x76\x8d\x66\x46\x2f\x85\xa3\xe7\x72\x7f\x01\x99\xb1\x43\x69\x66\xab\xfb\x13\xbd\x31\x34\x7f\x9c\x07\x69\xff\x6f\x45\xd8\x72\xb9\x1a\xc8\xc0\xb7\x85\xa3\x73\x1f\x0e\x15\xeb\xfb\x8f\xf3\xd7\x57\x9c\x27\xae\xf0\x55\x5a\x1e\x1a\x85\x66\x9e\x32\xf7\x06\xcf\x18\x72\x4a\x79\x6b\x0f\xab\xca\x0d\x2e\x33\x9b\xd3\xbc\x20\x66\x7d\x63\x75\xc9\x5a\xd1\x56\x4d\x72\xe5\xf6\xcf\xb7\x0c\x51\x71\xa1\xf4\xee\x5e\x93\x7e\x7e\x37\xe8\x11\x44\x5c\x4b\x61\xf5\x74\x6f\x2b\xac\xb1\xdc\x97\x8a\x85\x77\xe6\x92\xd5\x9a\xbc\xa5\x64\xcf\x31\xa7\xdd\xbc\xa2\xd9\x44\x85\x3f\x1d\x73\xba\x24\x7e\xc1\x36\x49\x9c\x30\x33\xa9\xb5\x40\xda\x87\x44\xce\xe6\x9f\xfb\x10\x85\x73\x99\xad\x0a\xae\xfc\xaa\xbb\x15\xb3\x16\xe7\x91\xc3\x8e\x50\x33\x7f\xa1\xf8\x51\x85\xc7\x95\xd5\xd8\x40\x7f\x98\xf2\x08\x79\x63\x50\xdf\xe3\x74\x3a\x9d\xfe\xfb\x19\x42\x68\x5d\xe0\x1b\xcd\x4b\xa5\xe9\xb5\xa3\x9b\xa4\x84\x0b\x43\x46\xcd\x85\xfb\xca\x8a\x6f\x62\xad\x64\x31\x09\xab\xd7\xcc\x2a\x5e\x4e\x3d\x97\xaa\x47\xf7\x7a\xfe\x66\x59\x38\x1c\x16\x8a\x57\x1a\x19\xf6\x2b\x89\x73\x0d\x7a\xcc\xaf\x23\x2b\xd7\x3a\xec\xcb\x77\x5c\xae\xe3\xde\xec\x63\x46\x08\xdd\xe7\x20\x8c\x19\xe1\xf0\x3b\x00\x00\xff\xff\x12\xcd\x7f\xc4\x52\x03\x00\x00")
func docGoBytes() ([]byte, error) {
@ -778,6 +820,10 @@ var _bindata = map[string]func() (*asset, error){
"1599641390_add_emoji_reactions_index.up.sql": _1599641390_add_emoji_reactions_indexUpSql,
"1599720851_add_seen_index_remove_long_messages.down.sql": _1599720851_add_seen_index_remove_long_messagesDownSql,
"1599720851_add_seen_index_remove_long_messages.up.sql": _1599720851_add_seen_index_remove_long_messagesUpSql,
"doc.go": docGo,
}
@ -848,6 +894,8 @@ var _bintree = &bintree{nil, map[string]*bintree{
"1598955122_add_mentions.up.sql": &bintree{_1598955122_add_mentionsUpSql, map[string]*bintree{}},
"1599641390_add_emoji_reactions_index.down.sql": &bintree{_1599641390_add_emoji_reactions_indexDownSql, map[string]*bintree{}},
"1599641390_add_emoji_reactions_index.up.sql": &bintree{_1599641390_add_emoji_reactions_indexUpSql, map[string]*bintree{}},
"1599720851_add_seen_index_remove_long_messages.down.sql": &bintree{_1599720851_add_seen_index_remove_long_messagesDownSql, map[string]*bintree{}},
"1599720851_add_seen_index_remove_long_messages.up.sql": &bintree{_1599720851_add_seen_index_remove_long_messagesUpSql, map[string]*bintree{}},
"doc.go": &bintree{docGo, map[string]*bintree{}},
}}

View File

@ -0,0 +1,2 @@
DROP INDEX seen_local_chat_id_idx;
UPDATE user_messages SET hide = 0 WHERE length(text) > 4096;

View File

@ -0,0 +1,2 @@
CREATE INDEX seen_local_chat_id_idx ON user_messages(local_chat_id, seen);
UPDATE user_messages SET hide = 1 WHERE length(text) > 4096;