Skip to content

Added support for local blocks.#34

Merged
svenrog merged 2 commits intomasterfrom
bugfix/local_blocks
May 16, 2025
Merged

Added support for local blocks.#34
svenrog merged 2 commits intomasterfrom
bugfix/local_blocks

Conversation

@svenrog
Copy link
Copy Markdown
Collaborator

@svenrog svenrog commented May 16, 2025

  • (Attempted) fix for issue with Lazy loading in ContentDelivery api.
  • Fix for issue with local blocks in 2.0.0.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Hello @svenrog, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

Hello team, Gemini here to provide a summary of this pull request. Based on the title and description, the primary intent of this PR is to address a couple of issues identified in the 2.0.0 release: an attempted fix for a lazy loading issue in the Content Delivery API and a fix specifically for issues related to local blocks. The changes involve updates to the changelog, minor code cleanup, refactoring of internal link data handling, and improvements to the lazy loading mechanism for link collections.

Highlights

  • Bug Fixes: This PR includes fixes aimed at resolving a lazy loading issue within the Content Delivery API and addressing problems encountered with local blocks in the 2.0.0 version.
  • Lazy Loading Thread Safety: Improved the thread safety of the lazy loading mechanism in PropertyLinkDataCollection by introducing a lock (_lazyLock) around the data loading logic in the Value getter.
  • Internal LinkData Refactoring: Refactored the internal LinkData class by changing IDictionary fields to Dictionary, removing an unused _pessimisticLock, and simplifying the GetAttributeKey method by removing the lock and using TryAdd.
  • Serialization Control: Added [SystemTextJsonIgnore] and [NewtonsoftJsonIgnore] attributes to the Attributes and IsReadOnly properties in LinkData to prevent these internal properties from being serialized, likely for API responses.
  • Collection Interface Change: Changed LinkDataCollection<TLinkData> to implement IList<TLinkData> in addition to IEnumerable<TLinkData>, providing more list-specific functionality.

Changelog

Click here to see the changelog
  • CHANGELOG.md
    • Added a new version section ## [2.0.1].
    • Documented the attempted fix for the Lazy loading issue in ContentDelivery api.
    • Documented the fix for the issue with local blocks in 2.0.0.
  • src/Geta.Optimizely.GenericLinks.ContentDeliveryApi/GenericLinkPropertyModel.cs
    • Removed a trailing space from the empty Expand method body.
  • src/Geta.Optimizely.GenericLinks/LinkData.cs
    • Changed the type of _attributes and _attributeKeys fields from IDictionary<string, string> to Dictionary<string, string> (Diff 1).
    • Removed the unused _pessimisticLock field (Diff 1).
    • Removed the initialization of _pessimisticLock in the constructor (Diff 2).
    • Added [SystemTextJsonIgnore] and [NewtonsoftJsonIgnore] attributes to the Attributes property (Diff 3).
    • Added [SystemTextJsonIgnore] and [NewtonsoftJsonIgnore] attributes to the IsReadOnly property (Diff 4).
    • Removed the lock (_pessimisticLock) block and simplified the logic in GetAttributeKey to use _attributeKeys.TryAdd (Diff 5).
  • src/Geta.Optimizely.GenericLinks/LinkDataCollection.cs
    • Changed the implemented interface from IEnumerable<TLinkData> to IList<TLinkData> (Diff 1).
  • src/Geta.Optimizely.GenericLinks/PropertyLinkDataCollection.cs
    • Added a new private readonly object field _lazyLock for thread synchronization (Diff 1).
    • Modified the Value getter to check ((ILazyProperty)this).HasLazyValue and use the _lazyLock to ensure thread-safe loading of _linkItemCollection (Diff 2).
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


Code flows like a stream,
Fixing bugs, a waking dream.
Tests pass, green and bright,
Code review, pure delight.
Merge it, hold it tight.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

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

Choose a reason for hiding this comment

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

Code Review

The pull request introduces several changes to the Geta.Optimizely.GenericLinks library, including fixes for lazy loading and local blocks. The changes touch various parts of the codebase, including data models, collections, and property handling. Overall, the changes seem reasonable, but there are a few areas that could be improved for clarity and efficiency.

Summary of Findings

  • Thread Safety: The removal of the lock in LinkData.cs and the introduction of TryAdd raises concerns about thread safety. While TryAdd is thread-safe, ensure that all other operations within the GetAttributeKey method are also thread-safe. The introduction of _lazyLock in PropertyLinkDataCollection.cs also needs scrutiny to ensure that the lazy loading mechanism is thread-safe and doesn't introduce any race conditions.
  • Lazy Loading: The lazy loading implementation in PropertyLinkDataCollection.cs uses a lock to ensure thread safety. Ensure that the LoadData method is thread-safe and doesn't have any potential race conditions, as this is a critical section.
  • Documentation: Consider adding more documentation to explain the purpose of the changes, especially the removal of the lock in LinkData.cs and the lazy loading implementation in PropertyLinkDataCollection.cs. This will help future developers understand the changes and avoid potential issues.

Merge Readiness

The pull request introduces important fixes for lazy loading and local blocks. However, the thread safety concerns and the lack of documentation in certain areas need to be addressed before merging. I recommend addressing these issues before merging. I am unable to approve this pull request, and other reviewers should review and approve this code before merging.

Comment thread src/Geta.Optimizely.GenericLinks/PropertyLinkDataCollection.cs
Comment thread src/Geta.Optimizely.GenericLinks/LinkData.cs
Comment thread src/Geta.Optimizely.GenericLinks/PropertyLinkDataCollection.cs
@sonarqubecloud
Copy link
Copy Markdown

@svenrog svenrog merged commit b24b874 into master May 16, 2025
3 of 4 checks passed
@svenrog svenrog deleted the bugfix/local_blocks branch May 16, 2025 14:10
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.

2 participants