forked from yougov/mongo-connector
-
Notifications
You must be signed in to change notification settings - Fork 6
fixing updates and skipping unnecessary updates #13
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
Open
benjamine
wants to merge
25
commits into
algolia:algolia
Choose a base branch
from
orchardmile:algolia
base: algolia
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Improvements to algolia doc manager
Adding more debugging information
Fixed missing casting
from other doc managers, as defaults are defined elsewhere and passed in
fixing dot notation regex
logging ignored mongo updates
fixing error a value is None
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
hi guys, this might be a big change to be merged lightly, but I'm sending it in case you guys find this, or part of this, useful.
1. skip updates based on filters
I added the
update_can_be_ignoredfunction that will use the json attributes_filter to filter the mongo update_spec ($set and $unset), if no field passed thru the filter, that means the update won't have any impact in the algolia index, so the update is skipped.we are using this to avoid a lot of unnecessary operations.
2. support updates when a postproc script is used
we realized this functionality is sort of broken right now, current behavior when an update arrive is:
the problem here is step 2, that apply_update is trying to apply an update that is for the original mongo document, to the algolia doc, which if you use a postproc script, will have a different structure.
Now, depending on how desctructive your postproc is, there's no way to recreate the doc from the algolia doc (the postproc result), for example, we index products, and we delete from the doc variants out of stock, but when an update comes saying stock is back, we need to readd it, that is impossible without grabbing the original mongo document.
If you check the Elastic Search doc manager, you'll notice they solved this problem by including the source doc (untransformed) as a child property
"source", but we didn't want to do that for 2 reasons:so we decided the cheapest and safest is to read the doc from mongo instead (unfortunately that means I had to modify the connector class to share the mongo connection with the doc manager).
the result is now, when an update arrives there are 4 possible results:
a. update skipped
if the update has $set and $unset, and the fields updated are all filtered out, update is skipped
cost: zero
b. doc replace
if the update is a doc replace, the update_spec is the full doc (no $set or $unset), so that is filter+remap+postproc, and sent to algolia
cost: 1 algolia operation
c. reprocessing original doc
if there is a postproc script, and a partial update, the doc is read from mongo (using the mongo client obtained from the connector), and the obtained doc is filter+remap+postproc, and sent to algolia
cost: 1 mongo read + 1 algolia operation
d. sending a partial update
if there is no postproc, then it is possible to convert the mongo update_spec into an algolia partial update, and that is sent as an algolia partial update.
cost: 1 algolia operation