Skip to content

Commit 394e041

Browse files
committed
Match repos using LOWER
Selects repos in a case-insensitive manner. Org and repo will be automatically converted to lowercase, and will match against the lowercased org and repo in the database. This allows for any repos that were previously indexed in a case-sensitive manner to still be matched correctly. Signed-off-by: hasheddan <[email protected]>
1 parent 61a1be8 commit 394e041

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

cmd/doc/main.go

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,13 @@ func raw(w http.ResponseWriter, r *http.Request) {
217217
repo := parameters["repo"]
218218
tag := parameters["tag"]
219219

220+
fullRepo := fmt.Sprintf("%s/%s/%s", "github.com", org, repo)
220221
var rows pgx.Rows
221222
var err error
222223
if tag == "" {
223-
rows, err = db.Query(context.Background(), "SELECT c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.id = (SELECT id FROM tags WHERE repo = $1 ORDER BY time DESC LIMIT 1);", "github.com"+"/"+org+"/"+repo)
224+
rows, err = db.Query(context.Background(), "SELECT c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.id = (SELECT id FROM tags WHERE LOWER(repo) = LOWER($1) ORDER BY time DESC LIMIT 1);", fullRepo)
224225
} else {
225-
rows, err = db.Query(context.Background(), "SELECT c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.name=$2;", "github.com"+"/"+org+"/"+repo, tag)
226+
rows, err = db.Query(context.Background(), "SELECT c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.name=$2;", fullRepo, tag)
226227
}
227228

228229
var res []byte
@@ -288,14 +289,15 @@ func org(w http.ResponseWriter, r *http.Request) {
288289
repo := parameters["repo"]
289290
tag := parameters["tag"]
290291
pageData := getPageData(r, fmt.Sprintf("%s/%s", org, repo), false)
292+
fullRepo := fmt.Sprintf("%s/%s/%s", "github.com", org, repo)
291293
b := &pgx.Batch{}
292294
if tag == "" {
293-
b.Queue("SELECT t.name, c.group, c.version, c.kind FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.id = (SELECT id FROM tags WHERE repo = $1 ORDER BY time DESC LIMIT 1);", "github.com"+"/"+org+"/"+repo)
295+
b.Queue("SELECT t.name, c.group, c.version, c.kind FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.id = (SELECT id FROM tags WHERE LOWER(repo) = LOWER($1) ORDER BY time DESC LIMIT 1);", fullRepo)
294296
} else {
295297
pageData.Title += fmt.Sprintf("@%s", tag)
296-
b.Queue("SELECT t.name, c.group, c.version, c.kind FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.name=$2;", "github.com"+"/"+org+"/"+repo, tag)
298+
b.Queue("SELECT t.name, c.group, c.version, c.kind FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.name=$2;", fullRepo, tag)
297299
}
298-
b.Queue("SELECT name FROM tags WHERE repo=$1 ORDER BY time DESC;", "github.com"+"/"+org+"/"+repo)
300+
b.Queue("SELECT name FROM tags WHERE LOWER(repo)=LOWER($1) ORDER BY time DESC;", fullRepo)
299301
br := db.SendBatch(context.Background(), b)
300302
defer br.Close()
301303
c, err := br.Query()
@@ -385,11 +387,12 @@ func doc(w http.ResponseWriter, r *http.Request) {
385387
return
386388
}
387389
pageData := getPageData(r, fmt.Sprintf("%s.%s/%s", kind, group, version), false)
390+
fullRepo := fmt.Sprintf("%s/%s/%s", "github.com", org, repo)
388391
var c pgx.Row
389392
if tag == "" {
390-
c = db.QueryRow(context.Background(), "SELECT t.name, c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.id = (SELECT id FROM tags WHERE repo = $1 ORDER BY time DESC LIMIT 1) AND c.group=$2 AND c.version=$3 AND c.kind=$4;", "github.com"+"/"+org+"/"+repo, group, version, kind)
393+
c = db.QueryRow(context.Background(), "SELECT t.name, c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.id = (SELECT id FROM tags WHERE repo = $1 ORDER BY time DESC LIMIT 1) AND c.group=$2 AND c.version=$3 AND c.kind=$4;", fullRepo, group, version, kind)
391394
} else {
392-
c = db.QueryRow(context.Background(), "SELECT t.name, c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE t.repo=$1 AND t.name=$2 AND c.group=$3 AND c.version=$4 AND c.kind=$5;", "github.com"+"/"+org+"/"+repo, tag, group, version, kind)
395+
c = db.QueryRow(context.Background(), "SELECT t.name, c.data::jsonb FROM tags t INNER JOIN crds c ON (c.tag_id = t.id) WHERE LOWER(t.repo)=LOWER($1) AND t.name=$2 AND c.group=$3 AND c.version=$4 AND c.kind=$5;", fullRepo, tag, group, version, kind)
393396
}
394397
foundTag := tag
395398
if err := c.Scan(&foundTag, crd); err != nil {

0 commit comments

Comments
 (0)