Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sort elements going into cache keys #1198

Merged
merged 2 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions qlty-check/src/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ struct InvocationCacheKey {
impl InvocationCacheKey {
fn build(&self) -> HashDigest {
let mut digest = HashDigest::new();

if let Some(runtime) = &self.plugin.runtime {
digest.add("plugin.runtime", &runtime.to_string());
}
Expand Down Expand Up @@ -143,7 +144,7 @@ impl InvocationCacheKey {
digest.add("plugin.download_type", download_type);
}

for environment in &self.plugin.environment {
for environment in self.plugin.environment.iter().sorted() {
if environment.list.is_empty() {
digest.add(
&format!("plugin.environment.{}", environment.name),
Expand Down Expand Up @@ -189,10 +190,12 @@ impl InvocationCacheKey {
&serde_yaml::to_string(output_category).unwrap(),
);
}

digest.add(
"plugin.driver.driver_type",
&serde_yaml::to_string(&driver.driver_type).unwrap(),
);

digest.add("plugin.driver.batch", &driver.batch.to_string());

digest.add("plugin.driver.max_batch", &driver.max_batch.to_string());
Expand All @@ -211,6 +214,7 @@ impl InvocationCacheKey {
"plugin.driver.target",
&serde_yaml::to_string(&driver.target).unwrap(),
);

digest.add(
"plugin.driver.invocation_directory_def",
&serde_yaml::to_string(&driver.invocation_directory_def).unwrap(),
Expand Down Expand Up @@ -239,11 +243,11 @@ impl InvocationCacheKey {
digest.add("tool", &self.tool.directory());
digest.add("driver_name", &self.driver_name);

for config in self.configs.clone().iter() {
for config in self.configs.clone().iter().sorted() {
digest.add(&config.path.to_string_lossy(), &config.contents);
}

for (path, contents) in &self.affects_cache {
for (path, contents) in self.affects_cache.iter().sorted() {
digest.add(&path.to_string_lossy(), contents);
}

Expand All @@ -261,7 +265,7 @@ impl IssuesCacheKey {
) -> Self {
let mut cache_busters = HashMap::new();

for affect_cache in affects_cache.iter() {
for affect_cache in affects_cache.iter().sorted() {
let path = PathBuf::from(affect_cache);
let contents = std::fs::read_to_string(&path).unwrap_or("".to_string());
cache_busters.insert(path, contents);
Expand All @@ -282,8 +286,10 @@ impl IssuesCacheKey {

pub fn finalize(&mut self, target: &Target) {
self.digest.add("target_path", &target.path_string());

self.digest
.add("target_contents_size", &target.contents_size.to_string());

self.digest.add(
"target_content_modified",
&target
Expand Down
12 changes: 12 additions & 0 deletions qlty-check/src/planner/config_files.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,18 @@ pub struct PluginConfigFile {
pub contents: String,
}

impl Ord for PluginConfigFile {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.path.cmp(&other.path)
}
}

impl PartialOrd for PluginConfigFile {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

impl PluginConfigFile {
pub fn from_path(path: &Path) -> Result<Self> {
let contents = fs::read_to_string(path)
Expand Down
14 changes: 13 additions & 1 deletion qlty-config/src/config/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -389,7 +389,7 @@ impl std::fmt::Display for PackageFileCandidate {
}
}

#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default)]
#[derive(Debug, Serialize, Deserialize, PartialEq, Clone, Default, Eq)]
pub struct PluginEnvironment {
#[serde(default)]
pub name: String,
Expand All @@ -401,6 +401,18 @@ pub struct PluginEnvironment {
pub value: String,
}

impl Ord for PluginEnvironment {
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
self.name.cmp(&other.name)
}
}

impl PartialOrd for PluginEnvironment {
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
Some(self.cmp(other))
}
}

#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq, Eq, Hash, Default)]
pub enum SuggestionMode {
#[default]
Expand Down
Loading