fix: Fix the serialization issue of nested attribute cache#2943
fix: Fix the serialization issue of nested attribute cache#2943wells1013 wants to merge 1 commit intoparse-community:alphafrom
Conversation
|
🚀 Thanks for opening this pull request! |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
📝 WalkthroughWalkthroughThe Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes 🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/ObjectStateMutations.ts (1)
229-256: The caching logic fix is correct; minor style nits.The fix correctly addresses the cache key mismatch:
_getDirtyObjectAttributesinParseObject.tslooks upobjectCache[attr]using top-level attribute keys (e.g.,"address"), so storing under the root key with the full parent object is the right approach.A few minor style issues:
- Lines 233-234 and 254-256 are missing semicolons, but the rest of the file consistently uses them.
- The
_restvariable is unused—you can simplify toattr.split('.')[0].- Line 237 uses
indexOf('.') >= 0while line 149 uses.includes('.')for the same check—consider being consistent.🔧 Suggested style cleanup
- // Initialize cache value and cache key - let cacheVal = val, - cacheKey = attr - - // Handle nested attributes (dot notation) - if (attr.indexOf('.') >= 0) { - // Split attribute path and use first key for caching - const [firstKey, ..._rest] = attr.split('.') - cacheKey = firstKey - // Get the actual value from server data using first key - cacheVal = serverData[firstKey] - } + // Initialize cache value and cache key + let cacheVal = val; + let cacheKey = attr; + + // Handle nested attributes (dot notation) + if (attr.includes('.')) { + // Use first path segment as cache key + cacheKey = attr.split('.')[0]; + // Get the actual value from server data using first key + cacheVal = serverData[cacheKey]; + }- const json = encode(cacheVal, false, true) - // Store serialized JSON string in object cache - objectCache[cacheKey] = JSON.stringify(json) + const json = encode(cacheVal, false, true); + // Store serialized JSON string in object cache + objectCache[cacheKey] = JSON.stringify(json);🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@src/ObjectStateMutations.ts` around lines 229 - 256, Fix small style issues in ObjectStateMutations: add missing semicolons after the declarations for cacheVal/cacheKey and after storing objectCache to match file style; replace "const [firstKey, ..._rest] = attr.split('.')" with a simpler extraction (e.g., use attr.split('.')[0] to derive firstKey) to remove the unused _rest; and use the same dot-check style as elsewhere by replacing "attr.indexOf('.') >= 0" with "attr.includes('.')" so the nestedSet/attr handling and objectCache population (cacheKey, cacheVal, encode, ParseObject/ParseFile/ParseRelation checks) are consistent with the rest of the module.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@src/ObjectStateMutations.ts`:
- Around line 229-256: Fix small style issues in ObjectStateMutations: add
missing semicolons after the declarations for cacheVal/cacheKey and after
storing objectCache to match file style; replace "const [firstKey, ..._rest] =
attr.split('.')" with a simpler extraction (e.g., use attr.split('.')[0] to
derive firstKey) to remove the unused _rest; and use the same dot-check style as
elsewhere by replacing "attr.indexOf('.') >= 0" with "attr.includes('.')" so the
nestedSet/attr handling and objectCache population (cacheKey, cacheVal, encode,
ParseObject/ParseFile/ParseRelation checks) are consistent with the rest of the
module.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: bf05eab1-f6b4-4235-af44-6a1eba436e5b
📒 Files selected for processing (1)
src/ObjectStateMutations.ts
Pull Request
Report security issues confidentially.
Any contribution is under this license.
Link this pull request to an issue.
Approach
This PR fixes a serialization issue in the nested attribute cache handling within the commitServerChanges function in ObjectStateMutations.ts. The issue was that when dealing with nested attributes (using dot notation like "address.street"), the caching mechanism was not properly handling the serialization and storage of these nested values.
Key Changes:
Fixed nested attribute cache key handling: When processing nested attributes (e.g., "address.street"), the code now correctly extracts the root key ("address") for caching purposes instead of using the full nested path.
Improved cache value retrieval: For nested attributes, the code now retrieves the entire parent object from server data rather than just the leaf value, ensuring proper serialization of the complete nested structure.
Summary by CodeRabbit