Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MAGE-1170: Handle Index options with IndexNameFetcher #1668

Open
wants to merge 3 commits into
base: release/3.15.0-dev
Choose a base branch
from

Conversation

damcou
Copy link
Contributor

@damcou damcou commented Jan 10, 2025

This PR contains:

  • Added an IndexOptions model implementing IndexOptionsInterface which would be the component of every index operation coming to AlgoliaConnector in the future
  • Updated the deprecated AlgoliaHelper class to convert all calls to the new format including IndexOptions model
  • Updated the AlgoliaConnector class so it fetches all index names according to the InderNameFetcher service
  • Removed all the static methods in AlgoliaConnector to be able to use the IndexNameFetcher everywhere, notably in the setLastOperationInfo methid

@damcou damcou requested a review from cammonro January 10, 2025 10:30
@damcou damcou self-assigned this Jan 10, 2025
Copy link
Contributor

@cammonro cammonro left a comment

Choose a reason for hiding this comment

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

Really like where you going with this. The IndexOptions is a very useful abstraction.

Added some questions and comments. Please let me know what you think.

*
* @return bool
*/
public function isTmp(): bool;
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should rename this to something more descriptive like:

Suggested change
public function isTmp(): bool;
public function isTemporaryIndex(): bool;

* @return string|null
*/
public function getEnforcedIndexName(): ?string;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add setters as well? Or save that for v3.16?

*
* @return string|null
*/
public function getEnforcedIndexName(): ?string;
Copy link
Contributor

Choose a reason for hiding this comment

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

Would enforcedIndexName be needed for anything other than legacy? If so maybe we don't need it in the interface?

Comment on lines +26 to +28
return $this->hasData(IndexOptionsInterface::IS_TMP) ?
(string) $this->getData(IndexOptionsInterface::IS_TMP) :
false;
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be (bool)?

Also since I believe DataObject will return null on getData() if not defined we could probably be less verbose (null will cast to false).

e.g.:

Suggested change
return $this->hasData(IndexOptionsInterface::IS_TMP) ?
(string) $this->getData(IndexOptionsInterface::IS_TMP) :
false;
return (bool) $this->getData(IndexOptionsInterface::IS_TMP);

Of course that relies on type juggling so your call here if you prefer to be explicit.


class IndexOptions extends DataObject implements IndexOptionsInterface
{
public function getStoreId(): ?int
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we add a doc block that null triggers the default store?

*/
public function copyQueryRules(string $fromIndexName, string $toIndexName, ?int $storeId = null): void
public function copyQueryRules(IndexOptionsInterface $fromIndexOptions, IndexOptionsInterface $toIndexOptions): void
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should call out via a doc block that copy operations cannot be performed across two different applications?

*/
public function moveIndex(string $fromIndexName, string $toIndexName, ?int $storeId = null): void
public function moveIndex(IndexOptions $fromIndexOptions, IndexOptions $toIndexOptions): void
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as for copy operations I'm thinking we should indicate that these cannot be performed across application IDs.

* @return string|null
* @throws NoSuchEntityException
*/
protected function getIndexName(IndexOptionsInterface $indexOptions): ?string
Copy link
Contributor

Choose a reason for hiding this comment

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

Would it make sense to relocate this getIndexName logic into the IndexOptions object itself?

}

if (is_null($indexOptions->getIndexSuffix())) {
return null;
Copy link
Contributor

Choose a reason for hiding this comment

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

Could this be an exception condition?

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