A social RSS reader built on the AT Protocol. glean.at
glean atproto atmosphere rss feed social app
14
fork

Configure Feed

Select the types of activity you want to include in your feed.

Increase SQL connection pool size

+17 -29
+17 -29
internal/db/db.go
··· 1 1 package db 2 2 3 3 import ( 4 - "context" 5 4 "database/sql" 6 5 "math" 7 6 "strings" ··· 10 9 "github.com/mattn/go-sqlite3" 11 10 ) 12 11 12 + func init() { 13 + sql.Register("sqlite3_glean", &sqlite3.SQLiteDriver{ 14 + ConnectHook: func(conn *sqlite3.SQLiteConn) error { 15 + if err := conn.RegisterFunc("exp", func(x float64) float64 { return math.Exp(x) }, true); err != nil { 16 + return err 17 + } 18 + if err := conn.RegisterFunc("log", func(x float64) float64 { return math.Log(x) }, true); err != nil { 19 + return err 20 + } 21 + return nil 22 + }, 23 + }) 24 + } 25 + 13 26 func NullStr(s string) sql.NullString { 14 27 return sql.NullString{String: s, Valid: s != ""} 15 28 } ··· 34 47 } 35 48 36 49 func Open(path string) (*DB, error) { 37 - db, err := sql.Open("sqlite3", path+"?_journal_mode=WAL&_busy_timeout=5000") 50 + db, err := sql.Open("sqlite3_glean", path+"?_journal_mode=WAL&_busy_timeout=5000") 38 51 if err != nil { 39 52 return nil, err 40 53 } 41 54 42 - db.SetMaxOpenConns(1) 43 - db.SetMaxIdleConns(2) 55 + db.SetMaxOpenConns(10) 56 + db.SetMaxIdleConns(5) 44 57 db.SetConnMaxLifetime(30 * time.Minute) 45 - 46 - conn, err := db.Conn(context.Background()) 47 - if err != nil { 48 - db.Close() 49 - return nil, err 50 - } 51 - 52 - err = conn.Raw(func(driverConn any) error { 53 - sqliteConn, ok := driverConn.(*sqlite3.SQLiteConn) 54 - if !ok { 55 - return nil 56 - } 57 - if err := sqliteConn.RegisterFunc("exp", func(x float64) float64 { return math.Exp(x) }, true); err != nil { 58 - return err 59 - } 60 - if err := sqliteConn.RegisterFunc("log", func(x float64) float64 { return math.Log(x) }, true); err != nil { 61 - return err 62 - } 63 - return nil 64 - }) 65 - _ = conn.Close() 66 - if err != nil { 67 - db.Close() 68 - return nil, err 69 - } 70 58 71 59 if err := initSchema(db); err != nil { 72 60 db.Close()