summaryrefslogtreecommitdiff
path: root/src/channel/app.rs
diff options
context:
space:
mode:
authorOwen Jacobson <owen@grimoire.ca>2024-10-01 22:30:04 -0400
committerOwen Jacobson <owen@grimoire.ca>2024-10-01 22:43:14 -0400
commitb8392a5fe824eff46f912a58885546e7b0f37e6f (patch)
treeff4061bbf4be30c53f84c179f86e8e6ab584dbda /src/channel/app.rs
parent7645411bcf7201e3a4927566da78080dc6a84ccf (diff)
Track event sequences globally, not per channel.
Per-channel event sequences were a cute idea, but it made reasoning about event resumption much, much harder (case in point: recovering the order of events in a partially-ordered collection is quadratic, since it's basically graph sort). The minor overhead of a global sequence number is likely tolerable, and this simplifies both the API and the internals.
Diffstat (limited to 'src/channel/app.rs')
-rw-r--r--src/channel/app.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/src/channel/app.rs b/src/channel/app.rs
index 70cda47..88f4170 100644
--- a/src/channel/app.rs
+++ b/src/channel/app.rs
@@ -3,8 +3,11 @@ use sqlx::sqlite::SqlitePool;
use crate::{
clock::DateTime,
- events::{broadcaster::Broadcaster, repo::message::Provider as _, types::ChannelEvent},
- repo::channel::{Channel, Provider as _},
+ events::{broadcaster::Broadcaster, types::ChannelEvent},
+ repo::{
+ channel::{Channel, Provider as _},
+ sequence::Provider as _,
+ },
};
pub struct Channels<'a> {
@@ -19,9 +22,10 @@ impl<'a> Channels<'a> {
pub async fn create(&self, name: &str, created_at: &DateTime) -> Result<Channel, CreateError> {
let mut tx = self.db.begin().await?;
+ let created_sequence = tx.sequence().next().await?;
let channel = tx
.channels()
- .create(name, created_at)
+ .create(name, created_at, created_sequence)
.await
.map_err(|err| CreateError::from_duplicate_name(err, name))?;
tx.commit().await?;
@@ -49,10 +53,10 @@ impl<'a> Channels<'a> {
let mut events = Vec::with_capacity(expired.len());
for channel in expired {
- let sequence = tx.message_events().assign_sequence(&channel).await?;
+ let deleted_sequence = tx.sequence().next().await?;
let event = tx
.channels()
- .delete_expired(&channel, sequence, relative_to)
+ .delete(&channel, relative_to, deleted_sequence)
.await?;
events.push(event);
}