Fix loading more torrents in conjunction with sorting ( default sorting is broken for now )
This commit is contained in:
parent
615734fd14
commit
08fd243a20
@ -211,25 +211,19 @@ func (db *postgresDatabase) QueryTorrents(
|
|||||||
// executeTemplate is used to prepare the SQL query, WITH PLACEHOLDERS FOR USER INPUT.
|
// executeTemplate is used to prepare the SQL query, WITH PLACEHOLDERS FOR USER INPUT.
|
||||||
sqlQuery := executeTemplate(`
|
sqlQuery := executeTemplate(`
|
||||||
SELECT id
|
SELECT id
|
||||||
, info_hash
|
, info_hash
|
||||||
, name
|
, name
|
||||||
, total_size
|
, total_size
|
||||||
, discovered_on
|
, discovered_on
|
||||||
, (SELECT COUNT(*) FROM files WHERE torrents.id = files.torrent_id) AS n_files
|
, (SELECT COUNT(*) FROM files WHERE torrents.id = files.torrent_id) AS n_files
|
||||||
{{ if .QueryExists }}
|
{{ if .QueryExists }}
|
||||||
, similarity(name, '{{ .Query }}') * -1 as relevance
|
, similarity(name, '{{ .Query }}') * -1 as relevance
|
||||||
{{ else }}
|
{{ else }}
|
||||||
, 0
|
, 0
|
||||||
{{ end }}
|
{{ end }}
|
||||||
FROM torrents
|
FROM torrents
|
||||||
{{ if not .FirstPage }}
|
{{ if not .FirstPage }}
|
||||||
WHERE
|
WHERE {{.OrderOn}} {{GTEorLTE .Ascending}} {{.LastOrderedValue}}
|
||||||
{{ if not .QueryExists }}
|
|
||||||
{{.OrderOn}}
|
|
||||||
{{ else }}
|
|
||||||
similarity(name, '{{ .Query }}') * -1
|
|
||||||
{{ end }}
|
|
||||||
{{GTEorLTE .Ascending}} {{.LastOrderedValue}}
|
|
||||||
{{ if .QueryExists }}
|
{{ if .QueryExists }}
|
||||||
AND
|
AND
|
||||||
{{ end }}
|
{{ end }}
|
||||||
@ -238,7 +232,7 @@ func (db *postgresDatabase) QueryTorrents(
|
|||||||
{{ if .QueryExists }}
|
{{ if .QueryExists }}
|
||||||
to_tsvector(regexp_replace(name, '\W+', ' ', 'g')) @@ websearch_to_tsquery('{{ .Query }}')
|
to_tsvector(regexp_replace(name, '\W+', ' ', 'g')) @@ websearch_to_tsquery('{{ .Query }}')
|
||||||
{{ end }}
|
{{ end }}
|
||||||
ORDER BY {{.OrderOn}} {{AscOrDesc .Ascending}}
|
ORDER BY {{.OrderOn}} {{AscOrDesc .Ascending}}
|
||||||
LIMIT {{.Limit}};
|
LIMIT {{.Limit}};
|
||||||
`, struct {
|
`, struct {
|
||||||
FirstPage bool
|
FirstPage bool
|
||||||
@ -352,8 +346,8 @@ func (db *postgresDatabase) GetTorrent(infoHash []byte) (*TorrentMetadata, error
|
|||||||
func (db *postgresDatabase) GetFiles(infoHash []byte) ([]File, error) {
|
func (db *postgresDatabase) GetFiles(infoHash []byte) ([]File, error) {
|
||||||
rows, err := db.conn.Query(`
|
rows, err := db.conn.Query(`
|
||||||
SELECT
|
SELECT
|
||||||
f.size,
|
f.size,
|
||||||
f.path
|
f.path
|
||||||
FROM files f, torrents t
|
FROM files f, torrents t
|
||||||
WHERE f.torrent_id = t.id AND t.info_hash = $1;`,
|
WHERE f.torrent_id = t.id AND t.info_hash = $1;`,
|
||||||
infoHash,
|
infoHash,
|
||||||
|
Loading…
Reference in New Issue
Block a user