Skip to content

Commit

Permalink
More fixes for revision listing and uniqueness
Browse files Browse the repository at this point in the history
  • Loading branch information
augustuswm committed Apr 12, 2024
1 parent 02d86a9 commit 6c1b31d
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ members = [
"parse-rfd",
"rfd-api",
"rfd-cli",
"rfd-data", "rfd-github",
"rfd-data",
"rfd-github",
"rfd-model",
"rfd-processor",
"rfd-redirect",
Expand Down
13 changes: 10 additions & 3 deletions rfd-api/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -779,7 +779,7 @@ impl ApiContext {
}
}

#[instrument(skip(self, caller))]
#[instrument(skip(self, caller, content))]
pub async fn update_rfd_content(
&self,
caller: &ApiCaller,
Expand Down Expand Up @@ -816,13 +816,20 @@ impl ApiContext {
let sha = latest_revision.commit_sha;
let mut github_locations = self
.github
.locations_for_commit(sha)
.locations_for_commit(sha.clone())
.await
.map_err(UpdateRfdContentError::GitHub)
.to_resource_result()?;

match github_locations.len() {
0 => Err(ResourceError::DoesNotExist),
0 => {
tracing::warn!(
sha,
rfd_number,
"Failed to find a GitHub location for most recent revision"
);
Err(ResourceError::DoesNotExist)
}
1 => {
// Unwrap is checked by the location length
let location = github_locations.pop().unwrap();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
DROP INDEX rfd_revision_commit_sha_idx;
CREATE UNIQUE INDEX rfd_revision_sha_idx ON rfd_revision (rfd_id, sha);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-- Your SQL goes here
5 changes: 4 additions & 1 deletion rfd-model/src/storage/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,10 @@ impl RfdRevisionStore for PostgresStore {
let query = query
.offset(pagination.offset)
.limit(pagination.limit)
.order((rfd_revision::rfd_id.asc(), rfd_revision::created_at.desc()));
.order((
rfd_revision::rfd_id.asc(),
rfd_revision::committed_at.desc(),
));

let results = query
.get_results_async::<RfdRevisionModel>(&*self.pool.get().await?)
Expand Down
10 changes: 8 additions & 2 deletions rfd-processor/src/rfd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -362,8 +362,14 @@ impl RemoteRfd {
.await?
.into_iter()
.next()
.map(|revision| revision.id)
.unwrap_or_else(|| Uuid::new_v4());
.map(|revision| {
tracing::info!("Found existing RFD revision for this commit. Updating the revision.");
revision.id
})
.unwrap_or_else(|| {
tracing::info!("No existing revisions exist for this commit. Creating a new revision.");
Uuid::new_v4()
});

let revision = RfdRevisionStore::upsert(
storage,
Expand Down

0 comments on commit 6c1b31d

Please sign in to comment.