mirror of
				https://github.com/superseriousbusiness/gotosocial.git
				synced 2025-10-30 21:12:24 -05:00 
			
		
		
		
	tweak db settings slightly (#238)
This commit is contained in:
		
					parent
					
						
							
								c7c9fff730
							
						
					
				
			
			
				commit
				
					
						ffc55e9b15
					
				
			
		
					 1 changed files with 11 additions and 0 deletions
				
			
		|  | @ -27,6 +27,7 @@ import ( | ||||||
| 	"errors" | 	"errors" | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"os" | 	"os" | ||||||
|  | 	"runtime" | ||||||
| 	"strings" | 	"strings" | ||||||
| 	"time" | 	"time" | ||||||
| 
 | 
 | ||||||
|  | @ -116,6 +117,7 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) | ||||||
| 			return nil, fmt.Errorf("could not create bundb postgres options: %s", err) | 			return nil, fmt.Errorf("could not create bundb postgres options: %s", err) | ||||||
| 		} | 		} | ||||||
| 		sqldb = stdlib.OpenDB(*opts) | 		sqldb = stdlib.OpenDB(*opts) | ||||||
|  | 		tweakConnectionValues(sqldb) | ||||||
| 		conn = WrapDBConn(bun.NewDB(sqldb, pgdialect.New()), log) | 		conn = WrapDBConn(bun.NewDB(sqldb, pgdialect.New()), log) | ||||||
| 	case dbTypeSqlite: | 	case dbTypeSqlite: | ||||||
| 		// SQLITE | 		// SQLITE | ||||||
|  | @ -133,6 +135,7 @@ func NewBunDBService(ctx context.Context, c *config.Config, log *logrus.Logger) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			return nil, fmt.Errorf("could not open sqlite db: %s", err) | 			return nil, fmt.Errorf("could not open sqlite db: %s", err) | ||||||
| 		} | 		} | ||||||
|  | 		tweakConnectionValues(sqldb) | ||||||
| 		conn = WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New()), log) | 		conn = WrapDBConn(bun.NewDB(sqldb, sqlitedialect.New()), log) | ||||||
| 
 | 
 | ||||||
| 		if c.DBConfig.Address == "file::memory:?cache=shared" { | 		if c.DBConfig.Address == "file::memory:?cache=shared" { | ||||||
|  | @ -319,10 +322,18 @@ func deriveBunDBPGOptions(c *config.Config) (*pgx.ConnConfig, error) { | ||||||
| 	cfg.TLSConfig = tlsConfig | 	cfg.TLSConfig = tlsConfig | ||||||
| 	cfg.Database = c.DBConfig.Database | 	cfg.Database = c.DBConfig.Database | ||||||
| 	cfg.PreferSimpleProtocol = true | 	cfg.PreferSimpleProtocol = true | ||||||
|  | 	cfg.RuntimeParams["application_name"] = c.ApplicationName | ||||||
| 
 | 
 | ||||||
| 	return cfg, nil | 	return cfg, nil | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | // https://bun.uptrace.dev/postgres/running-bun-in-production.html#database-sql | ||||||
|  | func tweakConnectionValues(sqldb *sql.DB) { | ||||||
|  | 	maxOpenConns := 4 * runtime.GOMAXPROCS(0) | ||||||
|  | 	sqldb.SetMaxOpenConns(maxOpenConns) | ||||||
|  | 	sqldb.SetMaxIdleConns(maxOpenConns) | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /* | /* | ||||||
| 	CONVERSION FUNCTIONS | 	CONVERSION FUNCTIONS | ||||||
| */ | */ | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue