mirror of
https://github.com/chatmail/core.git
synced 2026-04-02 05:22:14 +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) => {
|
||||
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
|
||||
.sql
|
||||
.execute(
|
||||
"UPDATE dns_cache
|
||||
SET timestamp = ?
|
||||
WHERE address = ?",
|
||||
(time(), resolved_addr.ip().to_string()),
|
||||
"INSERT INTO dns_cache (hostname, address, timestamp)
|
||||
VALUES (?, ?, ?)
|
||||
ON CONFLICT (hostname, address)
|
||||
DO UPDATE SET timestamp=excluded.timestamp",
|
||||
(host, resolved_addr.ip().to_string(), time()),
|
||||
)
|
||||
.await?;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user