backend: reduce number of concurrent db connections
This commit is contained in:
@@ -14,7 +14,7 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
init_tracing();
|
init_tracing();
|
||||||
|
|
||||||
let config = AppConfig::from_env()?;
|
let config = AppConfig::from_env()?;
|
||||||
let pool = db::init_pool(&config.database_url)?;
|
let pool = db::init_pool_with_size(&config.database_url, 1)?;
|
||||||
let s3_client = build_client(&config).await?;
|
let s3_client = build_client(&config).await?;
|
||||||
let storage = Arc::new(S3Storage::new(s3_client, config.s3_bucket.clone()));
|
let storage = Arc::new(S3Storage::new(s3_client, config.s3_bucket.clone()));
|
||||||
let jwt = JwtService::from_config(&config)?;
|
let jwt = JwtService::from_config(&config)?;
|
||||||
|
|||||||
+8
-1
@@ -5,10 +5,17 @@ use diesel::r2d2::{ConnectionManager, Pool};
|
|||||||
|
|
||||||
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
|
pub type PgPool = Pool<ConnectionManager<PgConnection>>;
|
||||||
|
|
||||||
|
const DEFAULT_MAX_POOL_SIZE: u32 = 2;
|
||||||
|
|
||||||
pub fn init_pool(database_url: &str) -> anyhow::Result<PgPool> {
|
pub fn init_pool(database_url: &str) -> anyhow::Result<PgPool> {
|
||||||
|
init_pool_with_size(database_url, DEFAULT_MAX_POOL_SIZE)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn init_pool_with_size(database_url: &str, max_size: u32) -> anyhow::Result<PgPool> {
|
||||||
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
let manager = ConnectionManager::<PgConnection>::new(database_url);
|
||||||
|
let pool_size = max_size.max(1);
|
||||||
let pool = Pool::builder()
|
let pool = Pool::builder()
|
||||||
.max_size(16)
|
.max_size(pool_size)
|
||||||
.connection_timeout(Duration::from_secs(10))
|
.connection_timeout(Duration::from_secs(10))
|
||||||
.build(manager)?;
|
.build(manager)?;
|
||||||
Ok(pool)
|
Ok(pool)
|
||||||
|
|||||||
+11
-11
@@ -323,8 +323,8 @@ const AppLayout = () => {
|
|||||||
const location = useLocation();
|
const location = useLocation();
|
||||||
const appState = useAppState();
|
const appState = useAppState();
|
||||||
const appDispatch = useAppDispatch();
|
const appDispatch = useAppDispatch();
|
||||||
const folderMatch = matchPath('/folders/:folderId', location.pathname);
|
const folderMatch = matchPath('/documents/folder/:folderId', location.pathname);
|
||||||
const nestedDocMatch = matchPath('/folders/:folderId/documents/:documentId', location.pathname);
|
const nestedDocMatch = matchPath('/documents/folder/:folderId/documents/:documentId', location.pathname);
|
||||||
const docMatch = nestedDocMatch || matchPath('/documents/:documentId', location.pathname);
|
const docMatch = nestedDocMatch || matchPath('/documents/:documentId', location.pathname);
|
||||||
const routeFolderId =
|
const routeFolderId =
|
||||||
folderMatch?.params?.folderId || nestedDocMatch?.params?.folderId || null;
|
folderMatch?.params?.folderId || nestedDocMatch?.params?.folderId || null;
|
||||||
@@ -1741,7 +1741,7 @@ const AppLayout = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = targetId === 'root' ? '/folders' : `/folders/${targetId}`;
|
const path = targetId === 'root' ? '/documents' : `/documents/folder/${targetId}`;
|
||||||
navigate(path, { replace });
|
navigate(path, { replace });
|
||||||
},
|
},
|
||||||
[loadFolder, navigate],
|
[loadFolder, navigate],
|
||||||
@@ -3155,7 +3155,7 @@ const AppLayout = () => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const path = targetId === 'root' ? '/folders' : `/folders/${targetId}`;
|
const path = targetId === 'root' ? '/documents' : `/documents/folder/${targetId}`;
|
||||||
navigate(path, { replace: false });
|
navigate(path, { replace: false });
|
||||||
},
|
},
|
||||||
[navigate, selectedFolder, loadFolder],
|
[navigate, selectedFolder, loadFolder],
|
||||||
@@ -4669,7 +4669,7 @@ const LoginRoute = () => {
|
|||||||
if (typeof target === 'string' && target.startsWith('/')) {
|
if (typeof target === 'string' && target.startsWith('/')) {
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
return '/folders';
|
return '/documents';
|
||||||
}, [location.state]);
|
}, [location.state]);
|
||||||
|
|
||||||
if (appStatus !== 'logged-out' && appStatus !== 'authenticating') {
|
if (appStatus !== 'logged-out' && appStatus !== 'authenticating') {
|
||||||
@@ -4734,17 +4734,17 @@ const AppRouter = () => (
|
|||||||
<Routes>
|
<Routes>
|
||||||
<Route path="/account/login" element={<LoginRoute />} />
|
<Route path="/account/login" element={<LoginRoute />} />
|
||||||
<Route element={<AppLayout />}>
|
<Route element={<AppLayout />}>
|
||||||
<Route path="/" element={<Navigate to="/folders" replace />} />
|
<Route path="/" element={<Navigate to="/documents" replace />} />
|
||||||
<Route path="/folders" element={<DocumentsRoute />} />
|
<Route path="/documents" element={<DocumentsRoute />} />
|
||||||
<Route path="/folders/:folderId" element={<DocumentsRoute />} />
|
<Route path="/documents/folder/:folderId" element={<DocumentsRoute />} />
|
||||||
<Route path="/documents/:documentId" element={<DocumentsRoute />} />
|
|
||||||
<Route
|
<Route
|
||||||
path="/folders/:folderId/documents/:documentId"
|
path="/documents/folder/:folderId/documents/:documentId"
|
||||||
element={<DocumentsRoute />}
|
element={<DocumentsRoute />}
|
||||||
/>
|
/>
|
||||||
|
<Route path="/documents/:documentId" element={<DocumentsRoute />} />
|
||||||
<Route path="/tags" element={<TagsRoute />} />
|
<Route path="/tags" element={<TagsRoute />} />
|
||||||
<Route path="/correspondents" element={<CorrespondentsRoute />} />
|
<Route path="/correspondents" element={<CorrespondentsRoute />} />
|
||||||
<Route path="*" element={<Navigate to="/folders" replace />} />
|
<Route path="*" element={<Navigate to="/documents" replace />} />
|
||||||
</Route>
|
</Route>
|
||||||
</Routes>
|
</Routes>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -782,6 +782,7 @@ button.icon-button.ghost:hover:not([disabled]) {
|
|||||||
|
|
||||||
.folder-row:hover {
|
.folder-row:hover {
|
||||||
background: var(--sidebar-hover-bg);
|
background: var(--sidebar-hover-bg);
|
||||||
|
color: var(--fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.folder-row.active {
|
.folder-row.active {
|
||||||
@@ -859,7 +860,7 @@ button.icon-button.ghost:hover:not([disabled]) {
|
|||||||
gap: 0.28rem;
|
gap: 0.28rem;
|
||||||
overflow-y: auto;
|
overflow-y: auto;
|
||||||
padding: 1.25rem;
|
padding: 1.25rem;
|
||||||
color: var(--sidebar-fg, #6f7683);
|
color: var(--sidebar-fg);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-section:first-of-type,
|
.sidebar-section:first-of-type,
|
||||||
|
|||||||
Reference in New Issue
Block a user