Skip to content

Fix Algolia status comparison endpoint #569

@hinzed1127

Description

@hinzed1127

The Problem

The status endpoint is a quick "health-check" endpoint that doesn't get functionally used by the site, but is purely for monitoring purposes. It is a quick way to view and discrepancies between Contentful data and the Algolia index.

There appears to be a handful of keys right now that are creating false mismatches between Contentful and Algolia, either due to some edge cases in null values not being caught properly, or quirks of what does or doesn't get shown as changed when the Contentful webhook gets fired that our update Algolia endpoint is the recipient of.

Technical causes

Reason why the children key mismatch keeps happening:

  • children gets calculated in loadPageMetadataMap, which only gets the latest value when initially adding a new page to the map. When a page removes or changes its parent, that only triggers an update in the algolia index for that page, not the parent whose children are changing.
    • Solution 1: remove children from the Algolia records entirely
    • Solution 2: when updating the parent for a record, also do the following:
      • If new parent value is null, then simply remove the current page from the old parent page's children array
      • If the new parent value is not null, remove the current page from the old parent and add it to the new parent's children array
    • Solution 2 is more effort and doesn't gain us anything at this time. Therefore, it probably makes sense to just quickly do solution 1 as a one-off solution.

Reason why the metaTitle and metaDescription mismatch keeps happening (I think):

  • The contentful webhook only includes defined values in updates it pushes out. Therefore, if a value is removed, it doesn't get included in the payload.
    • When comparison then happens in the SvelteKit API endpoint, it gets skipped entirely
    • Solution: make sure we explicitly check for those fields, as we should always be expecting them
    • Add-on to that solution: also include a "reset" endpoint for individual records, and not just a wholesale reset
      • Alternatively, make a reset endpoint that accepts an array of recordIds and resets all of those (i.e., this is the middle ground between a wholesale reset and an endpoint that can only reset individual records)

More recent issues

internalRedirect and externalRedirect appear to suffer from a similar null value issue, but the cause still needs to get diagnosed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions