Skip to content

feat: added a new field in settings screen, regarding maxConnection c…#72

Open
ealvesss wants to merge 4 commits intodebba:mainfrom
ealvesss:feat/max-conn-config
Open

feat: added a new field in settings screen, regarding maxConnection c…#72
ealvesss wants to merge 4 commits intodebba:mainfrom
ealvesss:feat/max-conn-config

Conversation

@ealvesss
Copy link

@ealvesss ealvesss commented Mar 6, 2026

PR Description

feat: make connection pool size configurable via Settings

Problem

The maximum number of database connections per pool was hardcoded in pool_manager.rs (10 for MySQL/PostgreSQL, 5 for SQLite), with no way for users to adjust it.

Changes

Backend (src-tauri/src/)

  • config.rs: Added max_connections: Option to AppConfig, its merge logic in save_config, and a get_pool_max_connections() helper that reads the config file without requiring AppHandle.
  • pool_manager.rs: Replaced all hardcoded .max_connections() values in MySQL, PostgreSQL, and SQLite pool creation with crate::config::get_pool_max_connections().

Frontend (src/)

  • contexts/SettingsContext.ts: Added maxConnections to the Settings interface and DEFAULT_SETTINGS.
  • pages/Settings.tsx: Added a number input for Connection Pool Size in the Data Editor section of the General settings tab.
  • i18n/locales/{en,it,es}.json: Added translation keys maxConnections, maxConnectionsDesc, and connections.

Behavior

  • The setting takes effect when a new connection pool is created. Users must disconnect and reconnect for changes to apply to existing connections.
  • Falls back to the default value if no config is present.

/// Get the configured maximum pool connections, or DEFAULT_MAX_CONNECTIONS if not set.
/// Does not require AppHandle — reads config.json directly via the paths module.
pub fn get_pool_max_connections() -> u32 {
let config_path = get_app_config_dir().join("config.json");
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

WARNING: get_pool_max_connections() may resolve a different config path than the rest of the app

get_app_config_dir() uses directories::ProjectDirs::from("", "", "tabularis"), while get_config_dir() uses app.path().app_config_dir() (Tauri's path resolver). On macOS, Tauri uses the bundle identifier to construct the config path (e.g., ~/Library/Application Support/com.tabularis.app/), while the directories crate uses the app name directly (e.g., ~/Library/Application Support/tabularis/). These can diverge, meaning get_pool_max_connections() may silently read from a different (possibly non-existent) config file and always return DEFAULT_MAX_CONNECTIONS.

Consider passing AppHandle to this function (like get_max_blob_size does) to ensure consistent path resolution, or at minimum add a test/log to verify the paths match.

@kilo-code-bot
Copy link

kilo-code-bot bot commented Mar 6, 2026

Code Review Summary

Status: 2 Issues Found | Recommendation: Address before merge

Overview

Severity Count
CRITICAL 2
WARNING 0
SUGGESTION 0
Issue Details (click to expand)

CRITICAL

File Line Issue
src-tauri/src/config.rs 145 Duplicate if config.plugins.is_some() block - identical code exists on lines 141-143
src/components/ui/NewConnectionModal.tsx 341 Logic bug: setFormData unconditionally overwrites preserved form data, making driver-specific preservation ineffective
Files Reviewed (11 files)
  • package-lock.json - Generated file, skipped
  • src-tauri/Cargo.lock - Generated file, skipped
  • src-tauri/src/commands.rs - Pool invalidation on connection update
  • src-tauri/src/config.rs - Added DEFAULT_MAX_CONNECTIONS constant; has duplicate code issue
  • src-tauri/src/models.rs - Added max_connections field to ConnectionParams
  • src-tauri/src/pool_manager.rs - Configurable max_connections for MySQL/PostgreSQL pools
  • src/components/ui/NewConnectionModal.tsx - Added max_connections UI and driver-specific form preservation; has logic bug
  • src/i18n/config.ts - Formatting changes only
  • src/i18n/locales/en.json - Added translations for max connections
  • src/i18n/locales/es.json - Added translations for max connections
  • src/i18n/locales/it.json - Added translations for max connections
  • src/i18n/locales/pt-br.json - Empty file added
  • src/pages/Connections.tsx - Added key prop to NewConnectionModal
  • src/pages/Settings.tsx - Whitespace change only
  • src/utils/connections.ts - Added max_connections field to interface

Fix these issues in Kilo Cloud

@debba
Copy link
Owner

debba commented Mar 7, 2026

@ealvesss Thanks for the contribution! The feature is well-structured overall, but there are a few issues to address before merging.

I have 2 points I would change:

  1. DEFAULT_MAX_CONNECTIONS = 1is a regression** — the previous hardcoded values were10for MySQL/PostgreSQL and5for SQLite. Defaulting to1` will serialize all queries and cause significant performance degradation for users who haven't explicitly configured the setting.

  2. SQLite needs a separate cap — SQLite only supports one concurrent writer, so high pool values will cause SQLITE_BUSY / database is locked errors. It should be capped independently (e.g. params.max_connections.map(|v| v.min(5)).unwrap_or(5)), not share the same configurable value as MySQL/PostgreSQL.

Design suggestion

Rather than a global setting in the Settings page, consider moving max_connections to the individual connection configuration (ConnectionParams). This would allow users to set:

  • max_connections: 1 for a PostgreSQL connection behind pgBouncer
  • max_connections: 10 for a direct MySQL connection
  • SQLite capped at 5 regardless

This approach is more flexible, more explicit, and makes the global AppConfig change unnecessary — which would simplify the diff considerably.

What do you think?

@ealvesss
Copy link
Author

@debba the "code-review" bots run again, after change the MR?

existing_config.plugins = config.plugins;
}

if config.plugins.is_some() {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Duplicate code - this if config.plugins.is_some() block is identical to the one on lines 141-143. This appears to be an accidental duplication during the merge. Remove lines 145-147.

}
setDriver(newDriver);

setFormData({
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CRITICAL: Logic bug - this setFormData call unconditionally overwrites all the form data that was carefully preserved/restored in lines 327-337. This makes the driver-specific form data preservation feature completely ineffective.

The code should either:

  1. Remove this hardcoded reset entirely, OR
  2. Move it before the preservation logic (lines 325-338), OR
  3. Merge the two setFormData calls so that preserved values are not lost

@debba
Copy link
Owner

debba commented Mar 12, 2026

@ealvesss Yes.
Btw I cannot run the project because I have the following issues:

error[E0382]: borrow of moved value: config.plugins
--> src/config.rs:145:12
|
142 | existing_config.plugins = config.plugins;
| -------------- value moved here
...
145 | if config.plugins.is_some() {
| ^^^^^^^^^^^^^^ value borrowed here after move
|
= note: move occurs because config.plugins has type std::option::Option<HashMap<std::string::String, config::PluginConfig>>, which does not implement the Copy trait

For more information about this error, try rustc --explain E0382.
error: could not compile tabularis (lib) due to 1 previous error

@ealvesss
Copy link
Author

@ealvesss Yes. Btw I cannot run the project because I have the following issues:

error[E0382]: borrow of moved value: config.plugins --> src/config.rs:145:12 | 142 | existing_config.plugins = config.plugins; | -------------- value moved here ... 145 | if config.plugins.is_some() { | ^^^^^^^^^^^^^^ value borrowed here after move | = note: move occurs because config.plugins has type std::option::Option<HashMap<std::string::String, config::PluginConfig>>, which does not implement the Copy trait

For more information about this error, try rustc --explain E0382. error: could not compile tabularis (lib) due to 1 previous error

here i can run properly.

how can I reproduce this error?

Copy link
Owner

@debba debba left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The config.plugins block in save_config is duplicated, causing a borrow-after-move compilation error. Remove the duplicate block (lines 145-148).

Comment on lines +145 to +148
if config.plugins.is_some() {
existing_config.plugins = config.plugins;
}

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This block is a duplicate of the one just above (lines 141-143). It causes a borrow-after-move compilation error because config.plugins is already moved on the first assignment.

Suggested change
if config.plugins.is_some() {
existing_config.plugins = config.plugins;
}

@debba
Copy link
Owner

debba commented Mar 16, 2026

@ealvesss sent the bug, if you can fix it and resolve conflicts, I will approve the pull request

@ealvesss
Copy link
Author

@ealvesss sent the bug, if you can fix it and resolve conflicts, I will approve the pull request

I will do it soon. Probably tomorrow!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants