Keep track of when files are last seen in the cache (#5214)

## Summary

And remove cached files that we haven't seen for a certain period of
time, currently 30 days.

For the last seen timestamp we actually use an `u64`, it's smaller on
disk than `SystemTime` (which size is OS dependent) and fits in an
`AtomicU64` which we can use to update it without locks.

## Test Plan

Added a new unit test, run by `cargo test`.
This commit is contained in:
Thomas de Zeeuw 2023-06-23 15:40:35 +02:00 committed by GitHub
parent 2dfa6ff58d
commit 1c638264b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 146 additions and 58 deletions

View file

@ -25,7 +25,7 @@ use ruff_python_ast::imports::ImportMap;
use ruff_python_ast::source_code::{LineIndex, SourceCode, SourceFileBuilder};
use ruff_python_stdlib::path::is_project_toml;
use crate::cache::{Cache, FileCache};
use crate::cache::Cache;
#[derive(Debug, Default, PartialEq)]
pub(crate) struct Diagnostics {
@ -208,10 +208,14 @@ pub(crate) fn lint_path(
let imports = imports.unwrap_or_default();
if let Some((cache, relative_path, file_last_modified)) = caching {
// We don't cache parsing errors.
if parse_error.is_none() {
// We don't cache parsing error.
let file_cache = FileCache::new(file_last_modified, &messages, &imports);
cache.update(relative_path.to_owned(), file_cache);
cache.update(
relative_path.to_owned(),
file_last_modified,
&messages,
&imports,
);
}
}