fix off-by-one error in visible messages for current channel

This commit is contained in:
2026-04-07 17:06:38 -04:00
parent c9cdc9cd37
commit 83661afd18
3 changed files with 3 additions and 6 deletions
+2 -1
View File
@@ -277,7 +277,8 @@ export const subscribe_to_channel = spacetimedb.reducer(
(ctx, { channelId }) => {
const hwm = ctx.db.channel_high_water_mark.channel_id.find(channelId);
const currentMax = hwm ? hwm.last_seq_id : 0n;
const earliest = currentMax > 100n ? currentMax - 100n : 0n;
// Sync exactly 100 messages (e.g. if max is 100, we want 1-100 inclusive, so earliest is 1)
const earliest = currentMax > 99n ? currentMax - 99n : 1n;
const existing = ctx.db.channel_subscription.identity.find(ctx.sender);
if (existing) {
+1
View File
@@ -308,6 +308,7 @@ export class MessagingService {
this.isLoadingMore = true;
try {
// Fetch exactly 100 more messages (inclusive range)
const newEarliest = oldestSeq > 100n ? oldestSeq - 100n : 1n;
this.#extendSubscriptionReducer({
-5
View File
@@ -86,11 +86,6 @@ const builder = DbConnection.builder()
// New Architecture: Good practice to subscribe to our own state
console.log("Subscribing to system configuration and user state...");
conn.subscriptionBuilder().subscribe([
"SELECT * FROM system_configuration",
`SELECT * FROM user WHERE identity = 0x${identity.toHexString()}`,
"SELECT * FROM my_channel_subscriptions"
]);
// Give it a brief moment to initialize before hammering
setTimeout(startStressTest, 1000);