Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 4de282d

Browse files
committedNov 12, 2024·
Fix runtime MBTile cache
1 parent d9a168c commit 4de282d

File tree

2 files changed

+43
-8
lines changed

2 files changed

+43
-8
lines changed
 

‎bbox-tile-server/src/store/mbtiles.rs

+42-7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use crate::store::{StoreFromConfig, TileReader, TileStore, TileStoreError, TileW
44
use async_trait::async_trait;
55
use bbox_core::{Compression, Format, TileResponse};
66
use log::info;
7-
use martin_mbtiles::{invert_y_value, CopyDuplicateMode, Metadata};
7+
use martin_mbtiles::{invert_y_value, Metadata};
88
use martin_tile_utils::Format as TileFormat;
99
use sqlx::{Acquire, Executor, Statement};
1010
use std::ffi::OsStr;
@@ -81,14 +81,49 @@ impl TileWriter for MbtilesDatasource {
8181
}
8282
async fn put_tile(&self, xyz: &Xyz, data: Vec<u8>) -> Result<(), TileStoreError> {
8383
let mut conn = self.pool.acquire().await?;
84-
self.mbtiles
85-
.insert_tiles(
86-
&mut conn,
87-
self.layout,
88-
CopyDuplicateMode::Override,
89-
&[(xyz.z, xyz.x as u32, xyz.y as u32, data)],
84+
// self.mbtiles
85+
// .insert_tiles(
86+
// &mut conn,
87+
// self.layout,
88+
// CopyDuplicateMode::Override,
89+
// &[(xyz.z, xyz.x as u32, xyz.y as u32, data)],
90+
// )
91+
// .await?;
92+
assert_eq!(
93+
self.layout,
94+
martin_mbtiles::MbtType::Normalized { hash_view: true }
95+
);
96+
// TODO: common code with put_tiles
97+
let mut tx = conn.begin().await?;
98+
let sql2 = tx
99+
.prepare(
100+
"INSERT OR IGNORE INTO images (tile_id, tile_data)
101+
VALUES (?1, ?2);",
90102
)
91103
.await?;
104+
let sql1 = tx
105+
.prepare(
106+
"INSERT OR REPLACE INTO map (zoom_level, tile_column, tile_row, tile_id)
107+
VALUES (?1, ?2, ?3, ?4);",
108+
)
109+
.await?;
110+
let (z, x, y, tile_data) = (&xyz.z, &(xyz.x as u32), &(xyz.y as u32), &data);
111+
let hash = blake3::hash(tile_data).to_hex();
112+
sql2.query()
113+
.bind(hash.as_str())
114+
.bind(tile_data)
115+
.execute(&mut *tx)
116+
.await?;
117+
118+
let y = invert_y_value(*z, *y);
119+
sql1.query()
120+
.bind(z)
121+
.bind(x)
122+
.bind(y)
123+
.bind(hash.as_str())
124+
.execute(&mut *tx)
125+
.await?;
126+
tx.commit().await?;
92127
Ok(())
93128
}
94129
async fn put_tiles(&mut self, tiles: &[(u8, u32, u32, Vec<u8>)]) -> Result<(), TileStoreError> {

‎bbox.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ cache = "filecache"
175175
[[tileset]]
176176
name = "ne_umn"
177177
map_service = { project = "ne", suffix = "map", layers = "country", tile_size = 512 }
178-
#cache = "mbtilecache"
178+
cache = "mbtilecache"
179179

180180
[[tileset]]
181181
name = "gebco"

0 commit comments

Comments
 (0)
Please sign in to comment.