mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-12-07 21:59:54 +00:00
LibRequests+RequestServer: Add a method to estimate disk cache size
This allows estimating the cache size stored on disk since a provided time stamp, and in total.
This commit is contained in:
parent
d5c00a493c
commit
ba49942b6d
Notes:
github-actions[bot]
2025-11-12 14:09:00 +00:00
Author: https://github.com/trflynn89
Commit: ba49942b6d
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/6675
Reviewed-by: https://github.com/gmta
Reviewed-by: https://github.com/konradekk
14 changed files with 138 additions and 3 deletions
|
|
@ -101,6 +101,7 @@ ErrorOr<CacheIndex> CacheIndex::create(Database::Database& database)
|
|||
statements.select_entry = TRY(database.prepare_statement("SELECT * FROM CacheIndex WHERE cache_key = ?;"sv));
|
||||
statements.update_response_headers = TRY(database.prepare_statement("UPDATE CacheIndex SET response_headers = ? WHERE cache_key = ?;"sv));
|
||||
statements.update_last_access_time = TRY(database.prepare_statement("UPDATE CacheIndex SET last_access_time = ? WHERE cache_key = ?;"sv));
|
||||
statements.estimate_cache_size_accessed_since = TRY(database.prepare_statement("SELECT SUM(data_size) + SUM(OCTET_LENGTH(response_headers)) FROM CacheIndex WHERE last_access_time >= ?;"sv));
|
||||
|
||||
return CacheIndex { database, statements };
|
||||
}
|
||||
|
|
@ -188,4 +189,21 @@ Optional<CacheIndex::Entry&> CacheIndex::find_entry(u64 cache_key)
|
|||
return m_entries.get(cache_key);
|
||||
}
|
||||
|
||||
Requests::CacheSizes CacheIndex::estimate_cache_size_accessed_since(UnixDateTime since) const
|
||||
{
|
||||
Requests::CacheSizes sizes;
|
||||
|
||||
m_database.execute_statement(
|
||||
m_statements.estimate_cache_size_accessed_since,
|
||||
[&](auto statement_id) { sizes.since_requested_time = m_database.result_column<u64>(statement_id, 0); },
|
||||
since);
|
||||
|
||||
m_database.execute_statement(
|
||||
m_statements.estimate_cache_size_accessed_since,
|
||||
[&](auto statement_id) { sizes.total = m_database.result_column<u64>(statement_id, 0); },
|
||||
UnixDateTime::earliest());
|
||||
|
||||
return sizes;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue