Check to see if this commit has mutable renames before looking it up

Summary: This doubles MySQL queries for now, but gives me a powerful point for caching (the `has_rename` method).

Reviewed By: mitrandir77

Differential Revision: D34527804

fbshipit-source-id: 762cd6644403cbb7fbf26369a13e726df1d4b58c
This commit is contained in:
Simon Farnsworth 2022-03-08 03:10:41 -08:00 committed by Facebook GitHub Bot
parent 389b98b050
commit 37c78a9062

View File

@ -167,6 +167,16 @@ impl MutableRenames {
Ok(())
}
async fn has_rename(&self, ctx: &CoreContext, dst_cs_id: ChangesetId) -> Result<bool, Error> {
ctx.perf_counters()
.increment_counter(PerfCounterType::SqlReadsReplica);
let rename_targets =
HasRenameCheck::query(&self.store.read_connection, &self.repo_id, &dst_cs_id).await?;
Ok(!rename_targets.is_empty())
}
pub async fn get_rename(
&self,
ctx: &CoreContext,
@ -176,6 +186,10 @@ impl MutableRenames {
ctx.perf_counters()
.increment_counter(PerfCounterType::SqlReadsReplica);
if !self.has_rename(ctx, dst_cs_id).await? {
return Ok(None);
}
let dst_path_bytes = path_bytes_from_mpath(dst_path.as_ref());
let dst_path_hash = PathHashBytes::new(&dst_path_bytes);
let mut rows = GetRename::query(
@ -251,4 +265,16 @@ queries! {
AND mutable_renames.dst_path_hash = {dst_path_hash}
"
}
read HasRenameCheck(repo_id: RepositoryId, dst_cs_id: ChangesetId) -> (ChangesetId) {
"
SELECT
mutable_renames.src_cs_id
FROM mutable_renames
WHERE
mutable_renames.repo_id = {repo_id}
AND mutable_renames.dst_cs_id = {dst_cs_id}
LIMIT 1
"
}
}