This commit is contained in:
lbenedar
2026-03-18 17:29:42 +03:00
parent 17267ed145
commit c4df79dffa
3 changed files with 7 additions and 1 deletions

View File

@@ -138,12 +138,14 @@ func (m MovieModel) GetAll(title string, genres []string, filter Filters) ([]*Mo
query := ` query := `
SELECT id, created_at, title, year, runtime, genres, version SELECT id, created_at, title, year, runtime, genres, version
FROM movies FROM movies
WHERE (to_tsvector('simple', title) @@ plainto_tsquery('simple', $1) OR $1 = '')
AND (genres @> $2 OR $2 = '{}')
ORDER BY id` ORDER BY id`
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel() defer cancel()
rows, err := m.DB.QueryContext(ctx, query) rows, err := m.DB.QueryContext(ctx, query, title, pq.Array(genres))
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@@ -0,0 +1,2 @@
DROP INDEX IF EXISTS movies_title_idx;
DROP INDEX IF EXISTS movies_genres_idx;

View File

@@ -0,0 +1,2 @@
CREATE INDEX IF NOT EXISTS movies_title_idx ON movies USING GIN (to_tsvector('simple', title));
CREATE INDEX IF NOT EXISTS movies_genres_idx ON movies USING GIN (genres);