Set arbitrary maximum size for tsvector column
- The max size for tsvector is 1 MiB - We index only the first million of characters, it should be enough for most feed entries.
This commit is contained in:
parent
715575001a
commit
a614f98063
3 changed files with 6 additions and 6 deletions
|
@ -142,7 +142,7 @@ alter table users add column extra hstore;
|
||||||
create index users_extra_idx on users using gin(extra);
|
create index users_extra_idx on users using gin(extra);
|
||||||
`,
|
`,
|
||||||
"schema_version_20": `alter table entries add column document_vectors tsvector;
|
"schema_version_20": `alter table entries add column document_vectors tsvector;
|
||||||
update entries set document_vectors = to_tsvector(title || ' ' || coalesce(content, ''));
|
update entries set document_vectors = to_tsvector(substring(title || ' ' || coalesce(content, '') for 1000000));
|
||||||
create index document_vectors_idx on entries using gin(document_vectors);`,
|
create index document_vectors_idx on entries using gin(document_vectors);`,
|
||||||
"schema_version_21": `alter table feeds add column user_agent text default '';`,
|
"schema_version_21": `alter table feeds add column user_agent text default '';`,
|
||||||
"schema_version_3": `create table tokens (
|
"schema_version_3": `create table tokens (
|
||||||
|
@ -192,7 +192,7 @@ var SqlMapChecksums = map[string]string{
|
||||||
"schema_version_18": "c0ec24847612c7f2dc326cf735baffba79391a56aedd73292371a39f38724a71",
|
"schema_version_18": "c0ec24847612c7f2dc326cf735baffba79391a56aedd73292371a39f38724a71",
|
||||||
"schema_version_19": "a83f77b41cc213d282805a5b518f15abbf96331599119f0ef4aca4be037add7b",
|
"schema_version_19": "a83f77b41cc213d282805a5b518f15abbf96331599119f0ef4aca4be037add7b",
|
||||||
"schema_version_2": "e8e9ff32478df04fcddad10a34cba2e8bb1e67e7977b5bd6cdc4c31ec94282b4",
|
"schema_version_2": "e8e9ff32478df04fcddad10a34cba2e8bb1e67e7977b5bd6cdc4c31ec94282b4",
|
||||||
"schema_version_20": "6c4e9b2c5bccdc3243c239c390fb1caa5e15624e669b2c07e14c126f6d2e2cd6",
|
"schema_version_20": "5d414c0cfc0da2863c641079afa58b7ff42dccb0f0e01c822ad435c3e3aa9201",
|
||||||
"schema_version_21": "77da01ee38918ff4fe33985fbb20ed3276a717a7584c2ca9ebcf4d4ab6cb6910",
|
"schema_version_21": "77da01ee38918ff4fe33985fbb20ed3276a717a7584c2ca9ebcf4d4ab6cb6910",
|
||||||
"schema_version_3": "a54745dbc1c51c000f74d4e5068f1e2f43e83309f023415b1749a47d5c1e0f12",
|
"schema_version_3": "a54745dbc1c51c000f74d4e5068f1e2f43e83309f023415b1749a47d5c1e0f12",
|
||||||
"schema_version_4": "216ea3a7d3e1704e40c797b5dc47456517c27dbb6ca98bf88812f4f63d74b5d9",
|
"schema_version_4": "216ea3a7d3e1704e40c797b5dc47456517c27dbb6ca98bf88812f4f63d74b5d9",
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
alter table entries add column document_vectors tsvector;
|
alter table entries add column document_vectors tsvector;
|
||||||
update entries set document_vectors = to_tsvector(title || ' ' || coalesce(content, ''));
|
update entries set document_vectors = to_tsvector(substring(title || ' ' || coalesce(content, '') for 1000000));
|
||||||
create index document_vectors_idx on entries using gin(document_vectors);
|
create index document_vectors_idx on entries using gin(document_vectors);
|
|
@ -50,7 +50,7 @@ func (s *Storage) UpdateEntryContent(entry *model.Entry) error {
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
UPDATE entries
|
UPDATE entries
|
||||||
SET document_vectors = to_tsvector(title || ' ' || coalesce(content, ''))
|
SET document_vectors = to_tsvector(substring(title || ' ' || coalesce(content, '') for 1000000))
|
||||||
WHERE id=$1 AND user_id=$2
|
WHERE id=$1 AND user_id=$2
|
||||||
`
|
`
|
||||||
_, err = tx.Exec(query, entry.ID, entry.UserID)
|
_, err = tx.Exec(query, entry.ID, entry.UserID)
|
||||||
|
@ -68,7 +68,7 @@ func (s *Storage) createEntry(entry *model.Entry) error {
|
||||||
INSERT INTO entries
|
INSERT INTO entries
|
||||||
(title, hash, url, comments_url, published_at, content, author, user_id, feed_id, document_vectors)
|
(title, hash, url, comments_url, published_at, content, author, user_id, feed_id, document_vectors)
|
||||||
VALUES
|
VALUES
|
||||||
($1, $2, $3, $4, $5, $6, $7, $8, $9, to_tsvector($1 || ' ' || coalesce($6, '')))
|
($1, $2, $3, $4, $5, $6, $7, $8, $9, to_tsvector(substring($1 || ' ' || coalesce($6, '') for 1000000)))
|
||||||
RETURNING id, status
|
RETURNING id, status
|
||||||
`
|
`
|
||||||
err := s.db.QueryRow(
|
err := s.db.QueryRow(
|
||||||
|
@ -107,7 +107,7 @@ func (s *Storage) updateEntry(entry *model.Entry) error {
|
||||||
query := `
|
query := `
|
||||||
UPDATE entries SET
|
UPDATE entries SET
|
||||||
title=$1, url=$2, comments_url=$3, content=$4, author=$5,
|
title=$1, url=$2, comments_url=$3, content=$4, author=$5,
|
||||||
document_vectors=to_tsvector($1 || ' ' || coalesce($4, ''))
|
document_vectors=to_tsvector(substring($1 || ' ' || coalesce($4, '') for 1000000))
|
||||||
WHERE user_id=$6 AND feed_id=$7 AND hash=$8
|
WHERE user_id=$6 AND feed_id=$7 AND hash=$8
|
||||||
RETURNING id
|
RETURNING id
|
||||||
`
|
`
|
||||||
|
|
Loading…
Reference in a new issue