Skip to content

Commit e626550

Browse files
chore: update maxminddb
Signed-off-by: Henry Gressmann <[email protected]>
1 parent cb6ea12 commit e626550

File tree

8 files changed

+99
-70
lines changed

8 files changed

+99
-70
lines changed

Cargo.lock

Lines changed: 68 additions & 36 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ r2d2={version="0.8", default-features=false}
7070
r2d2_sqlite="0.31"
7171
refinery={version="0.9", default-features=false}
7272
refinery-core={version="0.9", default-features=false}
73-
maxminddb={version="0.26", optional=true, features=["simdutf8"]}
73+
maxminddb={version="0.27", optional=true, features=["simdutf8"]}
7474

7575
[target.'cfg(not(target_env = "msvc"))'.dependencies]
7676
tikv-jemallocator="0.6"

biome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"$schema": "https://biomejs.dev/schemas/2.2.4/schema.json",
2+
"$schema": "./web/node_modules/@biomejs/biome/configuration_schema.json",
33
"assist": {
44
"enabled": true,
55
"actions": {

src/app/core/geoip.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,11 @@ pub struct LookupResult {
2424
pub country_code: Option<String>,
2525
}
2626

27-
#[derive(Clone)]
2827
pub struct LiwanGeoIP {
2928
pool: SqlitePool,
30-
reader: Arc<ArcSwapOption<maxminddb::Reader<Vec<u8>>>>,
29+
reader: ArcSwapOption<maxminddb::Reader<Vec<u8>>>,
3130

32-
downloading: Arc<AtomicBool>,
31+
downloading: AtomicBool,
3332
geoip: crate::config::GeoIpConfig,
3433
path: PathBuf,
3534
}
@@ -61,7 +60,7 @@ impl LiwanGeoIP {
6160
maxminddb::Reader::open_readfile(path.clone()).expect("Failed to open GeoIP database file").into()
6261
});
6362

64-
Ok(Self { geoip, pool, reader: ArcSwapOption::new(reader).into(), path, downloading: Default::default() })
63+
Ok(Self { geoip, pool, reader: ArcSwapOption::new(reader), path, downloading: Default::default() })
6564
}
6665

6766
fn is_enabled(&self) -> bool {
@@ -72,7 +71,7 @@ impl LiwanGeoIP {
7271
Self {
7372
geoip: Default::default(),
7473
pool,
75-
reader: ArcSwapOption::new(None).into(),
74+
reader: ArcSwapOption::new(None),
7675
downloading: Default::default(),
7776
path: PathBuf::new(),
7877
}
@@ -84,11 +83,9 @@ impl LiwanGeoIP {
8483
return Ok(Default::default());
8584
};
8685

87-
let lookup =
88-
reader.lookup::<maxminddb::geoip2::City>(*ip)?.ok_or_else(|| anyhow!("No data found for IP address"))?;
89-
90-
let city = lookup.city.and_then(|city| city.names.and_then(|names| names.get("en").map(|s| (*s).to_string())));
91-
let country_code = lookup.country.and_then(|country| country.iso_code.map(ToString::to_string));
86+
let lookup = reader.lookup(*ip)?.decode::<maxminddb::geoip2::City>().context("failed to decode data")?;
87+
let city = lookup.as_ref().and_then(|lookup| lookup.city.names.english.map(|v| v.to_string()));
88+
let country_code = lookup.and_then(|lookup| lookup.country.iso_code.map(|v| v.to_string()));
9289
Ok(LookupResult { city, country_code })
9390
}
9491

@@ -154,7 +151,7 @@ impl LiwanGeoIP {
154151
}
155152
}
156153

157-
pub fn keep_updated(geoip: LiwanGeoIP) {
154+
pub fn keep_updated(geoip: Arc<LiwanGeoIP>) {
158155
if !geoip.is_enabled() {
159156
return;
160157
}
@@ -230,11 +227,11 @@ async fn download_maxmind_db(edition: &str, account_id: &str, license_key: &str)
230227
entry.set_allow_external_symlinks(false);
231228
entry.set_preserve_permissions(false);
232229

233-
return Ok(entry
230+
return entry
234231
.unpack_in(folder)
235232
.await
236233
.context("Failed to unpack entry")?
237-
.ok_or_else(|| anyhow!("Failed to unpack entry"))?);
234+
.ok_or_else(|| anyhow!("Failed to unpack entry"));
238235
}
239236
}
240237
}

src/app/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ pub struct Liwan {
2525
pub onboarding: core::onboarding::LiwanOnboarding,
2626
pub entities: core::entities::LiwanEntities,
2727
pub projects: core::projects::LiwanProjects,
28-
pub geoip: core::geoip::LiwanGeoIP,
28+
pub geoip: Arc<core::geoip::LiwanGeoIP>,
2929

3030
pub config: Config,
3131
}
@@ -57,7 +57,7 @@ impl Liwan {
5757

5858
Ok(Self {
5959
#[cfg(feature = "geoip")]
60-
geoip: core::geoip::LiwanGeoIP::try_new(config.clone(), conn_app.clone())?,
60+
geoip: core::geoip::LiwanGeoIP::try_new(config.clone(), conn_app.clone())?.into(),
6161

6262
events: LiwanEvents::try_new(conn_events.clone(), conn_app.clone())?,
6363
onboarding: LiwanOnboarding::try_new(&conn_app)?,
@@ -79,7 +79,7 @@ impl Liwan {
7979

8080
Ok(Self {
8181
#[cfg(feature = "geoip")]
82-
geoip: core::geoip::LiwanGeoIP::try_new(config.clone(), conn_app.clone())?,
82+
geoip: core::geoip::LiwanGeoIP::try_new(config.clone(), conn_app.clone())?.into(),
8383

8484
events: LiwanEvents::try_new(conn_events.clone(), conn_app.clone())?,
8585
onboarding: LiwanOnboarding::try_new(&conn_app)?,

0 commit comments

Comments
 (0)