Skip to content

Commit

Permalink
fix: bookmark query by doing a case insensitive query (#6093)
Browse files Browse the repository at this point in the history
* Fix bookmark query by doing a case insensitive query

* Update index to be lower as well

* Update index

* Update admin/database/postgres/migrations/0053.sql

---------

Co-authored-by: Benjamin Egelund-Müller <[email protected]>
  • Loading branch information
AdityaHegde and begelundmuller authored Nov 19, 2024
1 parent b157eb7 commit c750fe7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
2 changes: 2 additions & 0 deletions admin/database/postgres/migrations/0053.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP INDEX bookmarks_search_idx;
CREATE INDEX bookmarks_search_idx ON bookmarks (project_id, resource_kind, lower(resource_name));
4 changes: 2 additions & 2 deletions admin/database/postgres/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -1783,7 +1783,7 @@ func (c *connection) DeleteProjectAccessRequest(ctx context.Context, id string)
// FindBookmarks returns a list of bookmarks for a user per project
func (c *connection) FindBookmarks(ctx context.Context, projectID, resourceKind, resourceName, userID string) ([]*database.Bookmark, error) {
var res []*database.Bookmark
err := c.getDB(ctx).SelectContext(ctx, &res, `SELECT * FROM bookmarks WHERE project_id = $1 and resource_kind = $2 and resource_name = $3 and (user_id = $4 or shared = true or "default" = true)`,
err := c.getDB(ctx).SelectContext(ctx, &res, `SELECT * FROM bookmarks WHERE project_id = $1 and resource_kind = $2 and lower(resource_name) = lower($3) and (user_id = $4 or shared = true or "default" = true)`,
projectID, resourceKind, resourceName, userID)
if err != nil {
return nil, parseErr("bookmarks", err)
Expand All @@ -1803,7 +1803,7 @@ func (c *connection) FindBookmark(ctx context.Context, bookmarkID string) (*data

func (c *connection) FindDefaultBookmark(ctx context.Context, projectID, resourceKind, resourceName string) (*database.Bookmark, error) {
res := &database.Bookmark{}
err := c.getDB(ctx).QueryRowxContext(ctx, `SELECT * FROM bookmarks WHERE project_id = $1 and resource_kind = $2 and resource_name = $3 and "default" = true`,
err := c.getDB(ctx).QueryRowxContext(ctx, `SELECT * FROM bookmarks WHERE project_id = $1 and resource_kind = $2 and lower(resource_name) = lower($3) and "default" = true`,
projectID, resourceKind, resourceName).StructScan(res)
if err != nil {
return nil, parseErr("bookmarks", err)
Expand Down

0 comments on commit c750fe7

Please sign in to comment.