Skip to content

Commit

Permalink
proper conn close
Browse files Browse the repository at this point in the history
  • Loading branch information
nyurik committed May 29, 2024
1 parent 793ee7e commit 23c6cd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 6 deletions.
10 changes: 6 additions & 4 deletions mbtiles/src/copier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use log::{debug, info, trace, warn};
use martin_tile_utils::{bbox_to_xyz, MAX_ZOOM};
use serde::{Deserialize, Serialize};
use sqlite_hashes::rusqlite::Connection;
use sqlx::{query, Executor as _, Row, SqliteConnection};
use sqlx::{query, Connection as _, Executor as _, Row, SqliteConnection};
use tilejson::Bounds;

use crate::errors::MbtResult;
Expand Down Expand Up @@ -137,7 +137,9 @@ impl MbtileCopierInt {
pub async fn run_simple(self) -> MbtResult<SqliteConnection> {
let mut conn = self.src_mbtiles.open_readonly().await?;
let src_type = self.src_mbtiles.detect_type(&mut conn).await?;
let mut conn = self.dst_mbtiles.open_or_new().await?;
conn.close().await?;

conn = self.dst_mbtiles.open_or_new().await?;
let is_empty_db = is_empty_database(&mut conn).await?;

let on_duplicate = if let Some(on_duplicate) = self.options.on_duplicate {
Expand Down Expand Up @@ -205,7 +207,7 @@ impl MbtileCopierInt {
} else {
dif_mbt.validate_diff_info(&dif_info, self.options.force)?;
}
drop(dif_conn);
dif_conn.close().await?;

let src_mbt = &self.src_mbtiles;
let mut src_conn = src_mbt.open_readonly().await?;
Expand All @@ -215,7 +217,7 @@ impl MbtileCopierInt {
}
let src_type = src_info.mbt_type;
src_mbt.validate_file_info(&src_info, self.options.force)?;
drop(src_conn);
src_conn.close().await?;

let dst_mbt = &self.dst_mbtiles;
let mut conn = dst_mbt.open_or_new().await?;
Expand Down
4 changes: 2 additions & 2 deletions mbtiles/src/patcher.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::path::PathBuf;

use log::{debug, info, warn};
use sqlx::query;
use sqlx::{query, Connection as _};

use crate::queries::detach_db;
use crate::MbtType::{Flat, FlatWithHash, Normalized};
Expand All @@ -18,7 +18,7 @@ pub async fn apply_patch(base_file: PathBuf, patch_file: PathBuf, force: bool) -
let patch_info = patch_mbt.get_diff_info(&mut conn).await?;
patch_mbt.validate_diff_info(&patch_info, force)?;
let patch_type = patch_info.mbt_type;
drop(conn);
conn.close().await?;

let mut conn = base_mbt.open().await?;
let base_info = base_mbt.get_diff_info(&mut conn).await?;
Expand Down

0 comments on commit 23c6cd1

Please sign in to comment.