nit on txs

This commit is contained in:
Ruben Fiszel
2024-02-06 16:40:43 +01:00
parent d1f3adade8
commit 89dc4dd4aa
5 changed files with 11 additions and 16 deletions

View File

@@ -191,13 +191,12 @@ async fn list_search_apps(
Path(w_id): Path<String>,
Extension(user_db): Extension<UserDB>,
) -> JsonResult<Vec<SearchApp>> {
let mut tx = user_db.begin(&authed).await?;
#[cfg(feature = "enterprise")]
let n = 1000;
#[cfg(not(feature = "enterprise"))]
let n = 3;
let mut tx = user_db.begin(&authed).await?;
let rows = sqlx::query_as!(
SearchApp,

View File

@@ -15,7 +15,6 @@ use axum::{
use serde::{Deserialize, Serialize};
use sqlx::FromRow;
use windmill_common::{
db::UserDB,
error::{self},
DB,
};
@@ -87,13 +86,9 @@ async fn update_config(
async fn delete_config(
Path(name): Path<String>,
Extension(db): Extension<DB>,
Extension(user_db): Extension<UserDB>,
authed: ApiAuthed,
) -> error::Result<String> {
let tx = user_db.begin(&authed).await?;
require_super_admin(&db, &authed.email).await?;
tx.commit().await?;
let deleted = sqlx::query!("DELETE FROM config WHERE name = $1 RETURNING name", name)
.fetch_all(&db)

View File

@@ -115,7 +115,6 @@ async fn windmill_migrations(migrator: &mut CustomMigrator, db: &DB) -> Result<(
#[cfg(feature = "enterprise")]
{
migrator.lock().await?;
let mut tx = db.begin().await?;
let has_done_migration = sqlx::query_scalar!(
"SELECT EXISTS(SELECT name FROM windmill_migrations WHERE name = 'bypassrls_1')",
)
@@ -126,6 +125,7 @@ async fn windmill_migrations(migrator: &mut CustomMigrator, db: &DB) -> Result<(
if !has_done_migration {
let query = include_str!("../../custom_migrations/bypassrls_1.sql");
tracing::info!("Applying bypassrls_1.sql");
let mut tx: sqlx::Transaction<'_, Postgres> = db.begin().await?;
tx.execute_many(query);
tracing::info!("Applied bypassrls_1.sql");
sqlx::query!("INSERT INTO windmill_migrations (name) VALUES ('bypassrls_1')")

View File

@@ -78,13 +78,12 @@ async fn list_search_flows(
Path(w_id): Path<String>,
Extension(user_db): Extension<UserDB>,
) -> JsonResult<Vec<SearchFlow>> {
let mut tx = user_db.begin(&authed).await?;
#[cfg(feature = "enterprise")]
let n = 1000;
#[cfg(not(feature = "enterprise"))]
let n = 3;
let mut tx = user_db.begin(&authed).await?;
let rows = sqlx::query_as!(
SearchFlow,

View File

@@ -68,13 +68,20 @@ impl UserDB {
where
T: Authable,
{
let mut tx = self.db.begin().await?;
let user = if authed.is_admin() {
"windmill_admin"
} else {
"windmill_user"
};
let (folders_write, folders_read): &(Vec<_>, Vec<_>) =
&authed.folders().into_iter().partition(|x| x.1);
let mut folders_read = folders_read.clone();
folders_read.extend(folders_write.clone());
let mut tx = self.db.begin().await?;
sqlx::query(&format!("SET LOCAL ROLE {}", user))
.execute(&mut *tx)
.await?;
@@ -105,11 +112,6 @@ impl UserDB {
.fetch_optional(&mut *tx)
.await?;
let (folders_write, folders_read): &(Vec<_>, Vec<_>) =
&authed.folders().into_iter().partition(|x| x.1);
let mut folders_read = folders_read.clone();
folders_read.extend(folders_write.clone());
sqlx::query!(
"SELECT set_config('session.folders_read', $1, true)",
folders_read