Skip to content

Commit b07cd77

Browse files
committed
refactor(oplog): avoid redundant listshots call by reusing results
1 parent 884c587 commit b07cd77

File tree

1 file changed

+1
-2
lines changed

1 file changed

+1
-2
lines changed

crates/but/src/oplog/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ pub(crate) fn restore_to_oplog(
122122
oplog_sha: &str,
123123
) -> anyhow::Result<()> {
124124
let project = Project::find_by_path(repo_path)?;
125+
let snapshots = but_api::undo::list_snapshots(project.id, 100, None, None)?;
125126

126127
// Parse the oplog SHA (support partial SHAs)
127128
let commit_sha_string = if oplog_sha.len() >= 7 {
128129
// Try to find a snapshot that starts with this SHA
129-
let snapshots = but_api::undo::list_snapshots(project.id, 100, None, None)?;
130130

131131
let matching_snapshot = snapshots
132132
.iter()
@@ -139,7 +139,6 @@ pub(crate) fn restore_to_oplog(
139139
};
140140

141141
// Get information about the target snapshot
142-
let snapshots = but_api::undo::list_snapshots(project.id, 100, None, None)?;
143142
let target_snapshot = snapshots
144143
.iter()
145144
.find(|snapshot| snapshot.commit_id.to_string() == commit_sha_string)

0 commit comments

Comments
 (0)