From f738b5fbb622339dfe9856f6a6fe2f874af28ca6 Mon Sep 17 00:00:00 2001 From: Liran Cohen Date: Fri, 4 Aug 2023 13:17:41 -0400 Subject: [PATCH] comments for further clarity around encodedData --- src/core/dwn-constant.ts | 1 + src/handlers/messages-get.ts | 3 ++- src/handlers/records-write.ts | 3 ++- src/store/storage-controller.ts | 1 + 4 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/core/dwn-constant.ts b/src/core/dwn-constant.ts index b50ab56e4..1223f0093 100644 --- a/src/core/dwn-constant.ts +++ b/src/core/dwn-constant.ts @@ -1,6 +1,7 @@ export class DwnConstant { /** * The maximum size in bytes of raw data that will be returned as `encodedData`. + * this is also the maximum size that we will store within MessageStore. */ public static readonly maxDataSizeAllowedToBeEncoded = 50_000; } \ No newline at end of file diff --git a/src/handlers/messages-get.ts b/src/handlers/messages-get.ts index 5f2f9a77d..90ebd0481 100644 --- a/src/handlers/messages-get.ts +++ b/src/handlers/messages-get.ts @@ -63,7 +63,8 @@ export class MessagesGetHandler implements MethodHandler { continue; } - // RecordsWrite specific handling + // RecordsWrite specific handling, if MessageStore has embedded `encodedData` return it with the entry. + // we store `encodedData` along with the message if the data is below a certain threshold. const recordsWrite = message as RecordsWriteMessageWithOptionalEncodedData; if (recordsWrite.encodedData !== undefined) { entry.encodedData = recordsWrite.encodedData; diff --git a/src/handlers/records-write.ts b/src/handlers/records-write.ts index a3b4ed554..5306b3663 100644 --- a/src/handlers/records-write.ts +++ b/src/handlers/records-write.ts @@ -92,8 +92,9 @@ export class RecordsWriteHandler implements MethodHandler { } try { + // if data is below the threshold, we store it within MessageStore if (message.descriptor.dataSize <= DwnConstant.maxDataSizeAllowedToBeEncoded) { - // processes and sets `encodedData` with appropriate data to be saved in MessageStore. + // processes and sets `encodedData` with appropriate data. messageWithOptionalEncodedData = await this.processEncodedData( message, dataStream, diff --git a/src/store/storage-controller.ts b/src/store/storage-controller.ts index fb4338fdc..6e0213c9d 100644 --- a/src/store/storage-controller.ts +++ b/src/store/storage-controller.ts @@ -79,4 +79,5 @@ export class StorageController { } } +// records with a data size below a threshold are stored within MessageStore with their data embedded export type RecordsWriteMessageWithOptionalEncodedData = RecordsWriteMessage & { encodedData?: string };