synced_commit_mapping: add get which returns a vec

Summary:
This method is a future of synced-commit-mapping: there can be multiple query
results and we should make a decision of whether it is acceptable for the
business logic in the business logic, rather than pick a random one.

In later diffs I will introduce the consumers for this method.

Reviewed By: mitrandir77

Differential Revision: D23574165

fbshipit-source-id: f256f82c9848f54e5096c6e50d42600bfd260081
This commit is contained in:
Kostia Balytskyi 2020-09-08 13:33:53 -07:00 committed by Facebook GitHub Bot
parent 8e2b7754c4
commit 39d1cd8a47

View File

@ -111,6 +111,15 @@ pub trait SyncedCommitMapping: Send + Sync {
target_repo_id: RepositoryId,
) -> BoxFuture<Option<(ChangesetId, Option<CommitSyncConfigVersion>)>, Error>;
/// Find all the mapping entries for a given source commit and target repo
fn get(
&self,
ctx: CoreContext,
source_repo_id: RepositoryId,
bcs_id: ChangesetId,
target_repo_id: RepositoryId,
) -> BoxFuture<Vec<(ChangesetId, Option<CommitSyncConfigVersion>)>, Error>;
/// Inserts equivalent working copy of a large bcs id. It's similar to mapping entry,
/// however there are a few differences:
/// 1) For (large repo, small repo) pair, many large commits can map to the same small commit
@ -157,6 +166,16 @@ impl SyncedCommitMapping for Arc<dyn SyncedCommitMapping> {
(**self).get_one(ctx, source_repo_id, bcs_id, target_repo_id)
}
fn get(
&self,
ctx: CoreContext,
source_repo_id: RepositoryId,
bcs_id: ChangesetId,
target_repo_id: RepositoryId,
) -> BoxFuture<Vec<(ChangesetId, Option<CommitSyncConfigVersion>)>, Error> {
(**self).get(ctx, source_repo_id, bcs_id, target_repo_id)
}
fn insert_equivalent_working_copy(
&self,
ctx: CoreContext,
@ -331,6 +350,68 @@ impl SyncedCommitMapping for SqlSyncedCommitMapping {
.boxify()
}
fn get(
&self,
_ctx: CoreContext,
source_repo_id: RepositoryId,
bcs_id: ChangesetId,
target_repo_id: RepositoryId,
) -> BoxFuture<Vec<(ChangesetId, Option<CommitSyncConfigVersion>)>, Error> {
STATS::gets.add_value(1);
SelectMapping::query(
&self.read_connection,
&source_repo_id,
&bcs_id,
&target_repo_id,
)
.and_then({
cloned!(self.read_master_connection);
move |rows| {
if rows.is_empty() {
STATS::gets_master.add_value(1);
SelectMapping::query(
&read_master_connection,
&source_repo_id,
&bcs_id,
&target_repo_id,
)
.left_future()
} else {
future::ok(rows).right_future()
}
}
})
.map(move |rows| {
let v: Vec<_> = rows
.iter()
.map(|row| {
let (
large_repo_id,
large_bcs_id,
_small_repo_id,
small_bcs_id,
ref version_name,
) = row;
let maybe_version_name: Option<CommitSyncConfigVersion> = match version_name {
Some(version_name) => {
Some(CommitSyncConfigVersion(version_name.to_owned()))
}
None => None,
};
if target_repo_id == *large_repo_id {
(*large_bcs_id, maybe_version_name)
} else {
(*small_bcs_id, maybe_version_name)
}
})
.collect();
v
})
.boxify()
}
fn insert_equivalent_working_copy(
&self,
ctx: CoreContext,