Skip to content

Conversation

@m4tx
Copy link
Member

@m4tx m4tx commented Dec 24, 2025

This makes the API more ergonomic, as Arc should really just be an implementation detail, rather than something exposed to the user.

This is a followup to the discussion here:
#419 (comment)

This makes the API more ergonomic, as `Arc` should really just be an
implementation detail, rather than something exposed to the user.

This is a followup to the discussion here:
#419 (comment)
@github-actions github-actions bot added the C-lib Crate: cot (main library crate) label Dec 24, 2025
@m4tx m4tx changed the title refactor: use Arc internally in Database refactor!: use Arc internally in Database Dec 24, 2025
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Database type to use Arc internally rather than exposing it in the public API, making the framework more ergonomic for users. The change treats reference counting as an implementation detail rather than a user concern.

  • Moved Arc wrapping inside Database struct and added Clone implementation
  • Removed RequestDb extractor in favor of direct Database extraction via FromRequestHead
  • Updated all type signatures throughout the codebase from Arc<Database> to Database

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated no comments.

Show a summary per file
File Description
cot/src/db.rs Core refactoring: wraps DatabaseImpl in Arc internally, adds Clone derive, updates all match expressions to dereference the Arc, removes redundant DatabaseBackend impl for Arc<Database>
cot/src/request/extractors.rs Removes RequestDb wrapper struct and implements FromRequestHead directly on Database type
cot/src/request.rs Updates RequestExt trait method signatures to return &Database instead of &Arc<Database>
cot/src/project.rs Updates all type signatures and trait bounds from Arc<Database> to Database throughout bootstrap and context types
cot/src/session/store/db.rs Updates DbStore to store Database instead of Arc<Database>, removes unused Arc import
cot/src/auth/db.rs Updates DatabaseUserBackend to store Database instead of Arc<Database>, removes unused Arc import
cot/src/test.rs Updates TestDatabase and TestRequestBuilder to use Database instead of Arc<Database> throughout
cot/src/openapi.rs Updates ApiOperationPart implementation from RequestDb to Database
examples/todo-list/src/main.rs Updates handler signatures to use db: Database extractor instead of RequestDb(db): RequestDb, adds Database to imports, removes RequestDb import
examples/forms/src/main.rs Updates handler signatures to use db: Database extractor instead of RequestDb(db): RequestDb, adds Database to imports, removes RequestDb import
examples/admin/src/main.rs Updates handler signatures to use db: Database extractor instead of RequestDb(db): RequestDb, adds Database to imports, removes RequestDb import

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link

github-actions bot commented Dec 24, 2025

🐰 Bencher Report

Brancharc-database
Testbedgithub-ubuntu-latest
Click to view all benchmark results
BenchmarkLatencyBenchmark Result
microseconds (µs)
(Result Δ%)
Upper Boundary
microseconds (µs)
(Limit %)
empty_router/empty_router📈 view plot
🚷 view threshold
6,064.30 µs
(+0.10%)Baseline: 6,058.53 µs
6,795.29 µs
(89.24%)
json_api/json_api📈 view plot
🚷 view threshold
1,039.80 µs
(+1.50%)Baseline: 1,024.45 µs
1,131.99 µs
(91.86%)
nested_routers/nested_routers📈 view plot
🚷 view threshold
951.80 µs
(+0.49%)Baseline: 947.18 µs
1,042.46 µs
(91.30%)
single_root_route/single_root_route📈 view plot
🚷 view threshold
914.14 µs
(+0.80%)Baseline: 906.84 µs
995.54 µs
(91.82%)
single_root_route_burst/single_root_route_burst📈 view plot
🚷 view threshold
17,438.00 µs
(-1.56%)Baseline: 17,715.17 µs
20,867.06 µs
(83.57%)
🐰 View full continuous benchmarking report in Bencher

m4tx added a commit that referenced this pull request Dec 24, 2025
Similarly to #432, this drops the `Arc` from `Arc<Cache>` in public APIs
to make the interfaces more ergonomic and easier to use for the users.
Copy link
Member

@seqre seqre left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copilot AI review requested due to automatic review settings December 28, 2025 12:26
@m4tx m4tx enabled auto-merge (squash) December 28, 2025 12:33
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@m4tx m4tx merged commit 9127da6 into master Dec 28, 2025
36 of 38 checks passed
@m4tx m4tx deleted the arc-database branch December 28, 2025 12:57
@cotbot cotbot bot mentioned this pull request Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-lib Crate: cot (main library crate)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants