diff --git a/api/configs/setup.go b/api/configs/setup.go index 400934a5..b5862503 100644 --- a/api/configs/setup.go +++ b/api/configs/setup.go @@ -14,6 +14,8 @@ import ( "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" "go.mongodb.org/mongo-driver/mongo/options" + "go.mongodb.org/mongo-driver/mongo/readconcern" + "go.mongodb.org/mongo-driver/mongo/readpref" ) type DBSingleton struct { @@ -25,18 +27,24 @@ var once sync.Once func ConnectDB() *mongo.Client { once.Do(func() { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - - client, err := mongo.Connect(context.Background(), options.Client().ApplyURI(GetEnvMongoURI())) + clientOptions := options.Client(). + ApplyURI(GetEnvMongoURI()). + SetMinPoolSize(5). + SetMaxPoolSize(100). + SetMaxConnIdleTime(10 * time.Minute). + SetConnectTimeout(10 * time.Second). + SetReadPreference(readpref.SecondaryPreferred()). + SetReadConcern(readconcern.Local()) + + client, err := mongo.Connect(context.Background(), clientOptions) if err != nil { log.Fatalf("Unable to create MongoDB client") } - defer cancel() - // ping the database - err = client.Ping(ctx, nil) - if err != nil { + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + if err = client.Ping(ctx, nil); err != nil { log.Fatalf("Unable to ping database") } @@ -115,18 +123,17 @@ var clubOnce sync.Once func ConnectClubsDB() *sql.DB { clubOnce.Do(func() { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) db, err := sql.Open("pgx", GetClubsDBUri()) if err != nil { log.Panic("Unable to connect to clubs database.") } + // ping the database + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - // ping the database - err = db.PingContext(ctx) - if err != nil { + if err = db.PingContext(ctx); err != nil { log.Panic("Unable to ping database") } diff --git a/api/controllers/section.go b/api/controllers/section.go index 58fcbd2d..c89323c3 100644 --- a/api/controllers/section.go +++ b/api/controllers/section.go @@ -355,4 +355,4 @@ func buildSectionPipeline(endpoint string, sectionQuery bson.M, paginate map[str } return append(append(append(baseStages, lookupStages...), replaceStages...), paginateStages...) -} \ No newline at end of file +} diff --git a/api/schema/objects.go b/api/schema/objects.go index ff80e04c..ebc73180 100644 --- a/api/schema/objects.go +++ b/api/schema/objects.go @@ -328,7 +328,7 @@ type AcademicCalendar struct { MidtermsDue string `bson:"midterms_due" json:"midterms_due"` UniversityClosings [][]string `bson:"university_closings" json:"university_closings"` NoClasses [][]string `bson:"no_classes" json:"no_classes"` - URL string `bson:"url" json:"url"` + URL string `bson:"url" json:"url"` } type AcademicCalendarSession struct { Name string `bson:"name" json:"name"` diff --git a/api/server.go b/api/server.go index fe8ee6d0..864c6caf 100644 --- a/api/server.go +++ b/api/server.go @@ -53,6 +53,10 @@ func main() { Dsn: "https://530f8e39f757b71ab26ad1aa12e17a4d@o4504918397353984.ingest.us.sentry.io/4509397160493056", TracesSampleRate: 1.0, EnableTracing: true, + IgnoreErrors: []string{ + "tls: internal error", + "socket was unexpectedly closed", + }, }); err != nil { log.Printf("Sentry initialization failed: %v\n", err) }