Giter VIP home page Giter VIP logo

Comments (6)

Swissbite avatar Swissbite commented on September 20, 2024 1

Two things to mention:

  1. Algolia updates an object 1:1, so there is no "partial Update" of an object.
  2. All of these calculations only serve to reduce the burden and cost to Algolia.

In the previous versions you could define the fields which acts as a hash.
Because of this, we calculated a hash post-query in the transformer function, and named that field hash.
And because our paths where not part of the content itself (the field slug is not a full qualified path on a server), we where able also to set that as a configuration.

Our configuration looked like:

{
      appId: GATSBY_ALGOLIA_APP_ID,
      apiKey: ALGOLIA_WRITE_API_KEY,
      indexName: `${GATSBY_ALGOLIA_INDEX_NAME_PREFIX}`
      queries: algoliaQueries(languageTag),
      enablePartialUpdates: true, // default: false <<-- This got removed due to the change of requiring the internal.contentDigest field.
      matchFields: ['path', 'hash'], // default: ['modified'] <<-- There was the interesting magic
      skipIndexing: skipAlgoliaIndexing, // default: false <<-- This got removed, which is another issue but simple to solve
    }

And our transformer for a single object in the data array response was like:

function transformer(item) {
 const result = {
      ...item,
      objectID: `${item.contentful_id}_${item.node_locale}`,
      hash: createHashFromInputData(item),
      path: createPathFor(item),
    };
}

If you are

  • aiming for a "one-size-fits-all" solution, you need to create a method that calculates hashes for each object tree or traverse all objects to calculate a hash over all contentDigest
  • aiming for a simple solution but open for any kind of data structure, re-enable the matchFields option and explain in your docs what is happening and why.

IMHO a "one-size-fits-all" solution will never be good enough. So let the creators / developers be responsible on how to calculate the hash.

--- Update: My poorly translated point 2 in the section things to mention.

from gatsby-plugin-algolia.

Haroenv avatar Haroenv commented on September 20, 2024

Yes, that's an interesting point, there was an issue yesterday as well (#181, cc @drooJohnson) that was linked to contentDigest not working as needed.

I see two options here:

  1. create a simple hash of the content of the record before indexing (takes some computing power, but likely isn't too bad)
  2. allow override of the "digestField" so people can compute their own hash / combine existing fields (simple, but not sure if this would be too discoverable)

If you have any idea of how it should be most discoverable, I'm open to ideas.

from gatsby-plugin-algolia.

Haroenv avatar Haroenv commented on September 20, 2024

Makes sense, although I'd like to clarify that the load minimisation is for the customers, not Algolia. You're paying for load so it's in your interest, not Algolia's, to minimise it.

In that case the simplest solution is to change internal.contentDigest to an option to override, matchFields as that name used to exist, still defaulting to ['internal.contentDigest'].

If you're interested in making this happen fast, you can make a pull request, which I'm happy to approve :)

from gatsby-plugin-algolia.

Archunan-MDLZ avatar Archunan-MDLZ commented on September 20, 2024

Hi @Swissbite Any update on this, same issue we are also facing with contentDigest. The post helped to narrow down the issue. Here is another thought, function transformer(item) { contentDigest we can add current time/timestamp/random hash, instead of adding new field. just a thought till your PR updated to plugin

from gatsby-plugin-algolia.

Haroenv avatar Haroenv commented on September 20, 2024

You're right, the best way to ensure you're in charge is by consistently using the internal.contentDigest field (which also means the code doesn't need to be updated to deal with an array of fields instead of only one.

from gatsby-plugin-algolia.

Haroenv avatar Haroenv commented on September 20, 2024

I added this to the FAQ and documentation, so I think this issue is handled for now.

from gatsby-plugin-algolia.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.