Skip to content

Commit

Permalink
BC-8431 - Broken tldraw docs when reloading (#38)
Browse files Browse the repository at this point in the history
  • Loading branch information
SevenWaysDP authored Nov 26, 2024
1 parent f36cf22 commit 7cb44fc
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion src/infra/redis/ioredis.adapter.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ describe(IoRedisAdapter.name, () => {
// @ts-ignore
const id = readBufferReply[0][0].toString();

const expectedProps = ['COUNT', 1000, 'BLOCK', 1000, 'STREAMS', computeRedisRoomStreamName, '0'];
const expectedProps = ['STREAMS', computeRedisRoomStreamName, '0'];

const expectedResult = [
{
Expand Down
10 changes: 1 addition & 9 deletions src/infra/redis/ioredis.adapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,7 @@ export class IoRedisAdapter implements RedisAdapter {
}

public async readMessagesFromStream(streamName: string): Promise<StreamMessagesReply> {
const reads = await this.redis.xreadBuffer(
'COUNT',
1000, // Adjust the count as needed
'BLOCK',
1000, // Adjust the block time as needed
'STREAMS',
streamName,
'0',
);
const reads = await this.redis.xreadBuffer('STREAMS', streamName, '0');

const streamReplyRes = mapToStreamMessagesReply(reads);

Expand Down
9 changes: 7 additions & 2 deletions src/infra/y-redis/api.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ export class Api {

public async getDoc(room: string, docid: string): Promise<YRedisDoc> {
const end = MetricsService.methodDurationHistogram.startTimer();

let docChanged = false;

const roomComputed = computeRedisRoomStreamName(room, docid, this.redisPrefix);
Expand Down Expand Up @@ -123,13 +122,19 @@ export class Api {

end();

return {
const response = {
ydoc,
awareness,
redisLastId: docMessages?.lastId.toString() ?? '0',
storeReferences: docstate?.references ?? null,
docChanged,
};

if (ydoc.store.pendingStructs !== null) {
console.warn(`Document ${room} has pending structs ${JSON.stringify(ydoc.store.pendingStructs)}.`);
}

return response;
}

public async destroy(): Promise<void> {
Expand Down
7 changes: 2 additions & 5 deletions src/infra/y-redis/subscriber.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
The original code from the `y-redis` repository is licensed under the AGPL-3.0 license.
https://github.com/yjs/y-redis
*/
import * as map from 'lib0/map';
import { RedisService } from '../redis/redis.service.js';
import { Api, createApiClient } from './api.service.js';
import { isSmallerRedisId } from './helper.js';
Expand Down Expand Up @@ -50,13 +51,9 @@ export class Subscriber {
}

public subscribe(stream: string, f: SubscriptionHandler): { redisId: string } {
const sub = this.subscribers.get(stream) ?? { fs: new Set<SubscriptionHandler>(), id: '0', nextId: null };
const sub = map.setIfUndefined(this.subscribers, stream, () => ({ fs: new Set(), id: '0', nextId: null }));
sub.fs.add(f);

if (!this.subscribers.has(stream)) {
this.subscribers.set(stream, sub);
}

return {
redisId: sub.id,
};
Expand Down

0 comments on commit 7cb44fc

Please sign in to comment.