a few minor mbtiles cleanups (#997)

This commit is contained in:
Yuri Astrakhan 2023-11-12 20:23:59 -05:00 committed by GitHub
parent e3b62f4ce1
commit 490be6b968
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 38 deletions

View File

@ -350,7 +350,7 @@ impl MbtileCopierInt {
| (Normalized { .. }, Normalized { .. }) => {}
(cli, dst) => {
return Err(MbtError::MismatchedTargetType(
self.options.dst_file.to_path_buf(),
self.options.dst_file.clone(),
dst,
cli,
))
@ -445,26 +445,7 @@ impl MbtileCopierInt {
fn query_for_dst(frm_db: &'static str, frm_type: MbtType, to_type: MbtType) -> String {
match to_type {
Flat => format!("{frm_db}.tiles"),
FlatWithHash => match frm_type {
Flat => format!(
"
(SELECT zoom_level, tile_column, tile_row, tile_data, md5_hex(tile_data) AS tile_hash
FROM {frm_db}.tiles)"
),
FlatWithHash => format!("{frm_db}.tiles_with_hash"),
Normalized { hash_view } => {
if hash_view {
format!("{frm_db}.tiles_with_hash")
} else {
format!(
"
(SELECT zoom_level, tile_column, tile_row, tile_data, map.tile_id AS tile_hash
FROM {frm_db}.map JOIN {frm_db}.images ON map.tile_id = images.tile_id)"
)
}
}
},
Normalized { .. } => match frm_type {
FlatWithHash | Normalized { .. } => match frm_type {
Flat => format!(
"
(SELECT zoom_level, tile_column, tile_row, tile_data, md5_hex(tile_data) AS tile_hash
@ -492,8 +473,7 @@ impl MbtileCopierInt {
fn get_tile_hash_expr(tbl: &str, typ: MbtType) -> String {
match typ {
Flat => format!("IIF({tbl}.tile_data ISNULL, NULL, md5_hex({tbl}.tile_data))"),
FlatWithHash => format!("{tbl}.tile_hash"),
Normalized { .. } => format!("{tbl}.tile_hash"),
FlatWithHash | Normalized { .. } => format!("{tbl}.tile_hash"),
}
}
@ -533,8 +513,9 @@ impl MbtileCopierInt {
} else {
tile_hash_expr = match dif_type {
Flat => ", COALESCE(md5_hex(difTiles.tile_data), '') as tile_hash",
FlatWithHash => ", COALESCE(difTiles.tile_hash, '') as tile_hash",
Normalized { .. } => ", COALESCE(difTiles.tile_hash, '') as tile_hash",
FlatWithHash | Normalized { .. } => {
", COALESCE(difTiles.tile_hash, '') as tile_hash"
}
};
diff_tiles = match dif_type {
Flat => "diffDb.tiles",

View File

@ -13,7 +13,7 @@ use futures::TryStreamExt;
use log::{debug, info, warn};
use martin_tile_utils::{Format, TileInfo};
use serde::ser::SerializeStruct;
use serde::Serialize;
use serde::{Serialize, Serializer};
use serde_json::{Value as JSONValue, Value};
use sqlite_hashes::register_md5_function;
use sqlx::sqlite::{SqliteConnectOptions, SqliteRow};
@ -39,19 +39,12 @@ pub struct Metadata {
pub json: Option<JSONValue>,
}
#[allow(clippy::trivially_copy_pass_by_ref)]
fn serialize_ti<S>(ti: &TileInfo, serializer: S) -> Result<S::Ok, S::Error>
where
S: serde::Serializer,
{
fn serialize_ti<S: Serializer>(ti: &TileInfo, serializer: S) -> Result<S::Ok, S::Error> {
let mut s = serializer.serialize_struct("TileInfo", 2)?;
s.serialize_field("format", &ti.format.to_string())?;
s.serialize_field(
"encoding",
match ti.encoding.content_encoding() {
None => "",
Some(v) => v,
},
ti.encoding.content_encoding().unwrap_or_default(),
)?;
s.end()
}
@ -60,7 +53,7 @@ where
pub const AGG_TILES_HASH: &str = "agg_tiles_hash";
/// Metadata key for a diff file,
/// describing the eventual AGG_TILES_HASH value once the diff is applied
/// describing the eventual [`AGG_TILES_HASH`] value once the diff is applied
pub const AGG_TILES_HASH_IN_DIFF: &str = "agg_tiles_hash_after_apply";
#[derive(Debug, Clone, Copy, Hash, PartialEq, Eq, EnumDisplay)]
@ -177,7 +170,7 @@ impl Mbtiles {
}
}
/// Attach this MBTiles file to the given SQLite connection as a given name
/// Attach this `MBTiles` file to the given `SQLite` connection as a given name
pub async fn attach_to<T>(&self, conn: &mut T, name: &str) -> MbtResult<()>
where
for<'e> &'e mut T: SqliteExecutor<'e>,

View File

@ -64,7 +64,7 @@ where
== 1)
}
/// Check if MBTiles has a table or a view named 'tiles_with_hash' with needed fields
/// Check if `MBTiles` has a table or a view named `tiles_with_hash` with needed fields
pub async fn has_tiles_with_hash<T>(conn: &mut T) -> MbtResult<bool>
where
for<'e> &'e mut T: SqliteExecutor<'e>,