ARK-Builders / ARK-Builders/ark-core

Discussion: API of `ResourceIndex` and `ResourceIndex::update_all()` Return Type

Open
#82 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
10
Forks
6
PR merge metrics
No merged PRs in 30d

Description

The return type of `ResourceIndex::update_all()` as currently implemented in #79 is:
```rust
/// Represents the result of an update operation on the ResourceIndex
#[derive(PartialEq, Debug)]
pub struct IndexUpdate {
/// Resources that were added during the update
added: HashMap>,
/// Resources that were removed during the update
removed: HashSet,
}
```
Here, `added` represents the new (either created or modified) resources in the index compared to the previous state, and `removed` represents the resources that were removed.

### Problem Statement
We allow multiple resources to have the same ID to account for:
- Resources with duplicate content
- Resources with different content but the same ID (when using a non-cryptographic hash function)

Consider an index with 3 resources sharing the same ID (hash). If one of these resources is removed and `update_all()` is called, what should the return value be?
- Should we consider the ID "removed" from the index? This wouldn't be accurate since the ID still exists in the index.
- Should we not report that the ID was "removed"? This could mislead users into thinking there was no change in the current index state, which is incorrect.

> Regardless of the decision, there should be a clear description of the decision taken and the expected API behavior for people using `ResourceIndex` as an external crate.

Let's discuss the best approach to handle this scenario and update the API documentation accordingly.

Related discussion: https://github.com/ARK-Builders/ark-core/pull/79#discussion_r1685516381

Contributor guide

Open the contributing guide

Research direction

Start with ResourceIndex::update_all() and the IndexUpdate type implemented in PR #79, then review the related discussion linked in this issue. Resolve how duplicate IDs should be represented in the return value and document the chosen behavior for external crate users.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
backend-api-design
Issue type
Documentation
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.