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

[bug]: "Write" hosts used for the POST /indexes/{index}/browse operation #741

Open
ivan-wolf opened this issue Sep 25, 2024 · 0 comments · May be fixed by #742
Open

[bug]: "Write" hosts used for the POST /indexes/{index}/browse operation #741

ivan-wolf opened this issue Sep 25, 2024 · 0 comments · May be fixed by #742

Comments

@ivan-wolf
Copy link

ivan-wolf commented Sep 25, 2024

Description

In v3 of the library, the "read" hosts were used (see https://github.com/algolia/algoliasearch-client-php/blob/v3/src/Iterators/ObjectIterator.php#L36).

In v4, the hosts are solely determined on the HTTP method (in this case POST), which leads to the use of the "write" hosts.

This can have drastic implications, as we've found out.
For example, when browsing objects just after an update, the update may not have been propagated.

In our case/app, it lead to the accidental deletion of records in the following scenario:

  1. Records are synchronized to the search index. For each record syncedOn: {sync_time} is set. Task completion is awaited.
  2. Stale records (in the search index) are identified through /browse (syncedOn < {sync_time}). All updated records are also included in the result ⚠️

Client

Search

Version

4.4.3

Relevant log output

[
   {
      "jsonPayload":{
         "message":"Algolia API client: Response received.",
         "context":{
            "method":"POST",
            "host":"https://{appId}.algolia.net/1/indexes/{index}/batch",
            "body":{
               "requests":[
                  {
                     "body":{
                        "objectID":"3bbfb6619dc41a84a3953ee717784b7f",
                        "syncedOn":1727261466
                     },
                     "action":"partialUpdateObjectNoCreate"
                  }
               ]
            },
            "response":{
               "taskID":2239298392002,
               "objectIDs":[
                  "3bbfb6619dc41a84a3953ee717784b7f"
               ]
            }
         }
      },
      "timestamp":"2024-09-25T10:51:07.786Z",
      "severity":"DEBUG",
      "receiveTimestamp":"2024-09-25T10:51:07.926957805Z"
   },
   {
      "jsonPayload":{
         "message":"Algolia API client: Response received.",
         "context":{
            "method":"GET",
            "host":"https://{appId}-dsn.algolia.net/1/indexes/{index}/task/2239298392002",
            "body":null,
            "response":{
               "status":"published",
               "pendingTask":false
            }
         }
      },
      "timestamp":"2024-09-25T10:51:09.877Z",
      "severity":"DEBUG",
      "receiveTimestamp":"2024-09-25T10:51:09.926139931Z"
   },
   {
      "jsonPayload":{
         "message":"Algolia API client: Response received.",
         "context":{
            "method":"POST",
            "host":"https://{appId}.algolia.net/1/indexes/{index}/browse",
            "body":{
               "hitsPerPage":1000,
               "filters":"syncedOn < 1727261466"
            },
            "response":{
               "query":"",
               "processingTimeMS":2,
               "hits":[
                  {
                     "synced_on":1727226487,
                     "objectID":"3bbfb6619dc41a84a3953ee717784b7f"
                  }
               ]
            }
         }
      },
      "timestamp":"2024-09-25T10:51:09.913Z",
      "severity":"DEBUG",
      "receiveTimestamp":"2024-09-25T10:51:09.926139931Z"
   }
]
@ivan-wolf ivan-wolf linked a pull request Sep 25, 2024 that will close this issue
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 a pull request may close this issue.

1 participant