mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 17:36:29 +03:00
feat: promote fallback DNS results to cached on successful use
For hardcoded built-in DNS results there is no cache entry in `dns_cache` table so they cannot be prioritized if DNS resolution never returned these results yet. If there is no entry, a new one should be created. SQL UPSERT does this.
This commit is contained in:
21
src/net.rs
21
src/net.rs
@@ -232,14 +232,25 @@ pub(crate) async fn connect_tcp(
|
|||||||
Ok(stream) => {
|
Ok(stream) => {
|
||||||
tcp_stream = Some(stream);
|
tcp_stream = Some(stream);
|
||||||
|
|
||||||
// Maximize priority of this cached entry.
|
// Update timestamp of this cached entry
|
||||||
|
// or insert a new one if cached entry does not exist.
|
||||||
|
//
|
||||||
|
// This increases priority of existing cached entries
|
||||||
|
// and copies fallback addresses from build-in cache
|
||||||
|
// into database cache on successful use.
|
||||||
|
//
|
||||||
|
// Unlike built-in cache,
|
||||||
|
// database cache is used even if DNS
|
||||||
|
// resolver returns a non-empty
|
||||||
|
// (but potentially incorrect and unusable) result.
|
||||||
context
|
context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE dns_cache
|
"INSERT INTO dns_cache (hostname, address, timestamp)
|
||||||
SET timestamp = ?
|
VALUES (?, ?, ?)
|
||||||
WHERE address = ?",
|
ON CONFLICT (hostname, address)
|
||||||
(time(), resolved_addr.ip().to_string()),
|
DO UPDATE SET timestamp=excluded.timestamp",
|
||||||
|
(host, resolved_addr.ip().to_string(), time()),
|
||||||
)
|
)
|
||||||
.await?;
|
.await?;
|
||||||
break;
|
break;
|
||||||
|
|||||||
Reference in New Issue
Block a user