launchbadge / sqlx

🧰 The Rust SQL Toolkit. An async, pure Rust SQL crate featuring compile-time checked queries without a DSL. Supports PostgreSQL, MySQL, and SQLite.
Apache License 2.0
13.15k stars 1.24k forks source link

feat(postgres): add PgAdvisoryLockGuardOwned #3442

Closed bonsairobo closed 3 weeks ago

bonsairobo commented 1 month ago

This new lock guard can own an Arc<PgAdvisoryLock> without any lifetime, allowing it to be moved into spawned tasks.

Fixes #3429

abonander commented 1 month ago

@bonsairobo (moving the design discussion here)

Re: https://github.com/launchbadge/sqlx/issues/3429#issuecomment-2295471364

Is this an optimization to avoid deeply cloning the AdvisoryLock?

The only thing is the memoization of the release query: https://github.com/launchbadge/sqlx/blob/main/sqlx-postgres/src/advisory_lock.rs#L40

Which isn't strictly necessary I suppose. I was trying to amortize the allocation but at the end of the day it's going to be copied into the connection's buffer anyway.

I'm not against just making the guard not borrow the lock anymore, but it'd be a breaking change to remove the lifetime parameter so it would have to wait for 0.9.0 if we went that route.

bonsairobo commented 1 month ago

I'm not against just making the guard not borrow the lock anymore, but it'd be a breaking change to remove the lifetime parameter so it would have to wait for 0.9.0 if we went that route.

That would be my preference. I'm OK to wait for a release.

abonander commented 1 month ago

If you'd like to make those changes then, I'll tag this as Breaking.

bonsairobo commented 3 weeks ago

Superseded by https://github.com/launchbadge/sqlx/pull/3495