Skip to content

Commit

Permalink
Don't update or announce an update in schema provider if a schema wit…
Browse files Browse the repository at this point in the history
…h this id exists already (#472)

* Lower logging level to debug in reduce task

* Don't update schema when it hasn't changed

* Add entry to CHANGELOG.md

---------

Co-authored-by: adz <x12@adz.garden>
  • Loading branch information
sandreae and adzialocha authored Jul 27, 2023
1 parent dafce36 commit 18841e0
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Don't check for `affected_rows` on task deletion [#461](https://github.com/p2panda/aquadoggo/pull/461)
- Do not critically fail when view does not exist due to race condition [#460](https://github.com/p2panda/aquadoggo/pull/460)
- Do nothing on log insertion conflict [#468](https://github.com/p2panda/aquadoggo/pull/468)
- Don't update or announce an update in schema provider if a schema with this id exists already [#472](https://github.com/p2panda/aquadoggo/pull/472)

### Open Sauce

Expand Down
13 changes: 11 additions & 2 deletions aquadoggo/src/schema/schema_provider.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ impl SchemaProvider {

/// Inserts or updates the given schema in this provider.
///
/// Returns `true` if a schema was updated and `false` if it was inserted.
/// Returns `true` if a schema was updated or it already existed in it's current state, and
/// `false` if it was inserted.
pub async fn update(&self, schema: Schema) -> Result<bool> {
if let Some(supported_schema) = self.supported_schema.as_ref() {
if !supported_schema.contains(schema.id()) {
Expand All @@ -120,8 +121,16 @@ impl SchemaProvider {
}
};

info!("Updating {}", schema.id().display());
let mut schemas = self.schemas.lock().await;
let schema_exists = schemas.get(schema.id()).is_some();

if schema_exists {
// Return true here as the schema already exists in it's current state so we don't
// need to mutate the schema store or announce any change.
return Ok(true);
}

info!("Updating {}", schema.id().display());
let is_update = schemas
.insert(schema.id().clone(), schema.clone())
.is_some();
Expand Down

0 comments on commit 18841e0

Please sign in to comment.