Skip to content

Commit

Permalink
comments and variables for clarity
Browse files Browse the repository at this point in the history
  • Loading branch information
LiranCohen committed Aug 4, 2023
1 parent 6aade30 commit d424f05
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Decentralized Web Node (DWN) SDK <!-- omit in toc -->

Code Coverage
![Statements](https://img.shields.io/badge/statements-97.53%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-94.52%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-93.82%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-97.53%25-brightgreen.svg?style=flat)
![Statements](https://img.shields.io/badge/statements-97.53%25-brightgreen.svg?style=flat) ![Branches](https://img.shields.io/badge/branches-94.53%25-brightgreen.svg?style=flat) ![Functions](https://img.shields.io/badge/functions-93.82%25-brightgreen.svg?style=flat) ![Lines](https://img.shields.io/badge/lines-97.53%25-brightgreen.svg?style=flat)


- [Introduction](#introduction)
Expand Down
14 changes: 11 additions & 3 deletions src/handlers/records-write.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,10 @@ export class RecordsWriteHandler implements MethodHandler {

const isLatestBaseState = true;
const indexes = await constructRecordsWriteIndexes(recordsWrite, isLatestBaseState);

// if data is below a certain threshold, we embed the data directly into the message for storage in MessageStore.
let messageWithOptionalEncodedData: RecordsWriteMessageWithOptionalEncodedData = message;

// try to store data, unless options explicitly say to skip storage
if (options === undefined || !options.skipDataStorage) {
if (dataStream === undefined && newestExistingMessage?.descriptor.method === DwnMethodName.Delete) {
Expand All @@ -89,7 +93,8 @@ export class RecordsWriteHandler implements MethodHandler {

try {
if (message.descriptor.dataSize <= DwnConstant.maxDataSizeAllowedToBeEncoded) {
message = await this.processEncodedData(
// processes and sets `encodedData` with appropriate data to be saved in MessageStore.
messageWithOptionalEncodedData = await this.processEncodedData(
message,
dataStream,
newestExistingMessage as (RecordsWriteMessage|RecordsDeleteMessage) | undefined
Expand All @@ -111,7 +116,7 @@ export class RecordsWriteHandler implements MethodHandler {
}
}

await this.messageStore.put(tenant, message, indexes);
await this.messageStore.put(tenant, messageWithOptionalEncodedData, indexes);
await this.eventLog.append(tenant, await Message.getCid(message));

const messageReply = {
Expand All @@ -127,7 +132,10 @@ export class RecordsWriteHandler implements MethodHandler {
};

/**
* Embeds the given data into the `encodedData` property to be stored in the MessageStore instead of DataStore
* Embeds the record's data into the `encodedData` property.
* If dataStream is present, it uses the dataStream. Otherwise, uses the `encodedData` from the most recent RecordsWrite.
*
* @returns {RecordsWriteMessageWithOptionalEncodedData} `encodedData` embedded.
*
* @throws {DwnError} with `DwnErrorCode.RecordsWriteMissingDataInPrevious`
* if `dataStream` is absent AND `encodedData` of previous message is missing
Expand Down

0 comments on commit d424f05

Please sign in to comment.