Skip to content

fix(storage): treat bracketed metadata and context keys as literal keys in update - #15095

Draft
Dhriti07 wants to merge 1 commit into
mainfrom
storage-metadata-keys
Draft

Dhriti07 wants to merge 1 commit into
mainfrom
storage-metadata-keys

Conversation

@Dhriti07

Copy link
Copy Markdown
Contributor

Treat bracketed metadata and context keys as literal keys in update.

…ys in update

Treat bracketed metadata and context keys as literal keys in update.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a parseArrays parameter to the JSON utility methods in JsonUtils to control whether bracketed keys (e.g., x[2]) are parsed as arrays or treated as literal keys. This parameter is set to false when updating contexts and metadata fields in StorageImpl.java to prevent incorrect array parsing. The reviewer suggested a performance optimization in JsonUtils.treeify to check the parseArrays flag before instantiating and running the regex matcher, which avoids unnecessary overhead when array parsing is disabled.

Comment on lines 204 to 208
Matcher matcher = array_part.matcher(split);
if (matcher.matches()) {
if (parseArrays && matcher.matches()) {
name = matcher.group(1);
String idxString = matcher.group(2);
idx = Integer.parseInt(idxString);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

When parseArrays is false, creating a Matcher and running the regex match is unnecessary. Checking parseArrays first avoids this overhead.

          if (parseArrays) {
            Matcher matcher = array_part.matcher(split);
            if (matcher.matches()) {
              name = matcher.group(1);
              String idxString = matcher.group(2);
              idx = Integer.parseInt(idxString);
            }
          }

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant