Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Bitwarden
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Packages & Registries
Packages & Registries
Container Registry
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
TeDomum
Bitwarden
Commits
296063e1
Unverified
Commit
296063e1
authored
Oct 10, 2020
by
Daniel García
Committed by
GitHub
Oct 10, 2020
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1108 from rfwatson/add-db-connections-setting
Add DATABASE_MAX_CONNS config setting
parents
1842a796
b9daa59e
Pipeline
#2079
passed with stage
in 15 minutes and 59 seconds
Changes
3
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
1 deletion
+18
-1
.env.template
.env.template
+4
-0
src/config.rs
src/config.rs
+10
-0
src/db/mod.rs
src/db/mod.rs
+4
-1
No files found.
.env.template
View file @
296063e1
...
...
@@ -20,6 +20,10 @@
## - https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING
# DATABASE_URL=postgresql://user:password@host[:port]/database_name
## Database max connections
## Define the size of the connection pool used for connecting to the database.
# DATABASE_MAX_CONNS=10
## Individual folders, these override %DATA_FOLDER%
# RSA_KEY_FILENAME=data/rsa_key
# ICON_CACHE_FOLDER=data/icon_cache
...
...
src/config.rs
View file @
296063e1
...
...
@@ -222,6 +222,8 @@ make_config! {
data_folder
:
String
,
false
,
def
,
"data"
.to_string
();
/// Database URL
database_url
:
String
,
false
,
auto
,
|
c
|
format!
(
"{}/{}"
,
c
.data_folder
,
"db.sqlite3"
);
/// Database connection pool size
database_max_conns
:
u32
,
false
,
def
,
10
;
/// Icon cache folder
icon_cache_folder
:
String
,
false
,
auto
,
|
c
|
format!
(
"{}/{}"
,
c
.data_folder
,
"icon_cache"
);
/// Attachments folder
...
...
@@ -429,6 +431,14 @@ fn validate_config(cfg: &ConfigItems) -> Result<(), Error> {
// Validate connection URL is valid and DB feature is enabled
DbConnType
::
from_url
(
&
cfg
.database_url
)
?
;
let
limit
=
256
;
if
cfg
.database_max_conns
<
1
||
cfg
.database_max_conns
>
limit
{
err!
(
format!
(
"`DATABASE_MAX_CONNS` contains an invalid value. Ensure it is between 1 and {}."
,
limit
,
));
}
let
dom
=
cfg
.domain
.to_lowercase
();
if
!
dom
.starts_with
(
"http://"
)
&&
!
dom
.starts_with
(
"https://"
)
{
err!
(
"DOMAIN variable needs to contain the protocol (http, https). Use 'http[s]://bw.example.com' instead of 'bw.example.com'"
);
...
...
src/db/mod.rs
View file @
296063e1
...
...
@@ -51,7 +51,10 @@ macro_rules! generate_connections {
{
paste
::
paste!
{
[
<
$name
_
migrations
>
]::
run_migrations
()
?
;
}
let
manager
=
ConnectionManager
::
new
(
&
url
);
let
pool
=
Pool
::
builder
()
.build
(
manager
)
.map_res
(
"Failed to create pool"
)
?
;
let
pool
=
Pool
::
builder
()
.max_size
(
CONFIG
.database_max_conns
())
.build
(
manager
)
.map_res
(
"Failed to create pool"
)
?
;
return
Ok
(
Self
::
$name
(
pool
));
}
#[cfg(not(
$
name))]
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment