diff --git a/backend/go.mod b/backend/go.mod index 39b17f95..c96377d0 100644 --- a/backend/go.mod +++ b/backend/go.mod @@ -12,7 +12,9 @@ require ( require ( github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect golang.org/x/crypto v0.17.0 // indirect + golang.org/x/sync v0.1.0 // indirect golang.org/x/text v0.14.0 // indirect ) diff --git a/backend/pkg/db/db.go b/backend/pkg/db/db.go index 682bef87..7b11e22f 100644 --- a/backend/pkg/db/db.go +++ b/backend/pkg/db/db.go @@ -6,12 +6,12 @@ import ( "log" "sync" - "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgxpool" "github.com/metakgp/iqps/backend/pkg/config" ) var ( - database *pgx.Conn + database *pgxpool.Pool mu sync.Mutex ) @@ -34,12 +34,12 @@ create index IF NOT EXISTS idx_course_name_trgm on iqps using gin (course_name g ` -func InitDB() *pgx.Conn { +func InitDB() *pgxpool.Pool { var err error dbConfig := config.Get().DB psqlconn := fmt.Sprintf("host=%s port=%d user=%s password=%s dbname=%s sslmode=disable", dbConfig.Host, dbConfig.Port, dbConfig.Username, dbConfig.Password, dbConfig.DBname) // database, err = sql.Open("postgres", psqlconn) - database, err = pgx.Connect(context.Background(), psqlconn) + database, err = pgxpool.New(context.Background(), psqlconn) if err != nil { panic("Invalid Database connection string") } @@ -58,7 +58,7 @@ func InitDB() *pgx.Conn { return database } -func GetDB() *pgx.Conn { +func GetDB() *pgxpool.Pool { if database == nil { mu.Lock() defer mu.Unlock() diff --git a/backend/query/queries.go b/backend/query/queries.go index e4307f38..45495501 100644 --- a/backend/query/queries.go +++ b/backend/query/queries.go @@ -65,6 +65,7 @@ with fuzzy as ( from iqps where (course_code || ' ' || course_name) %>> @query_text order by rank_ix + limit 30 ), full_text as ( select @@ -77,6 +78,7 @@ full_text as ( fts_course_details @@ websearch_to_tsquery(@query_text) AND approve_status = true order by rank_ix + limit 30 ), partial_search as ( select id, @@ -88,6 +90,7 @@ partial_search as ( websearch_to_tsquery('simple', @query_text)::text || ':*' ) AND approve_status = true + limit 30 ), result as ( select iqps.id,iqps.course_code, iqps.course_name, iqps.year, iqps.exam, iqps.filelink, iqps.from_library, iqps.upload_timestamp, iqps.approve_status