Skip to content

Commit f8e9979

Browse files
authored
Merge pull request #17 from hackmdio/feature/add-debug-logging-for-get-doc
feature/add debug logging for getDoc
2 parents 56f2b03 + c0bad3b commit f8e9979

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/api.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import * as env from 'lib0/environment'
1313
import * as logging from 'lib0/logging'
1414

1515
const logWorker = logging.createModuleLogger('@y/redis/api/worker')
16-
// const logApi = logging.createModuleLogger('@y/redis/api')
16+
const logApi = logging.createModuleLogger('@y/redis/api')
1717

1818
let ydocUpdateCallback = env.getConf('ydoc-update-callback')
1919
if (ydocUpdateCallback != null && ydocUpdateCallback.slice(-1) !== '/') {
@@ -226,10 +226,12 @@ export class Api {
226226
async getDoc (room, docid) {
227227
const ms = extractMessagesFromStreamReply(await this.redis.xRead(redis.commandOptions({ returnBuffers: true }), { key: computeRedisRoomStreamName(room, docid, this.prefix), id: '0' }), this.prefix)
228228
const docMessages = ms.get(room)?.get(docid) || null
229+
if (docMessages?.messages) logApi(`processing messages of length: ${docMessages?.messages.length} in room: ${room}`)
229230
const docstate = await this.store.retrieveDoc(room, docid)
230231
const ydoc = new Y.Doc()
231232
const awareness = new awarenessProtocol.Awareness(ydoc)
232233
awareness.setLocalState(null) // we don't want to propagate awareness state
234+
const now = performance.now()
233235
ydoc.transact(() => {
234236
if (docstate) { Y.applyUpdateV2(ydoc, docstate.doc) }
235237
docMessages?.messages.forEach(m => {
@@ -248,6 +250,7 @@ export class Api {
248250
}
249251
})
250252
})
253+
logApi(`took ${performance.now() - now}ms to process messages for room: ${room}`)
251254
return { ydoc, awareness, redisLastId: docMessages?.lastId.toString() || '0', storeReferences: docstate?.references || null }
252255
}
253256

0 commit comments

Comments
 (0)