Anki Forums

Post-sync hook?

What would be the correct place to add a post-sync hook?

I have an addon that updates an external site with data about how many cards are caught up on reviews. Previously I was monkey patching to be able to run the update after syncing to pick up on the reviews done on a mobile device. It broke in 2.1.28. I’d like to do it properly this time.

Probably before the reset on main.py:892

Thanks!

Why before rather than after? I’d like to pass the collection as an argument and I don’t know if the reset affects anything.

reset() rebuilds the review queues. Putting the hook before it ensures that if an add-on modifies things, the queues will accurately reflect the state of the database after the add-ons are done.

Okay, that makes sense. My addon doesn’t modify but instead needs to be able to accurately count cards are/aren’t due in a deck or tag etcetera. Will that be accurate before the reset? If not should my addon run reset itself? Or should there be two separate hooks, one for addons that modify and one for addons that don’t?

Thanks.

If you’re calling getCard() or counts() you’ll need to reset first. If you’re querying the database directly there is no need.

1 Like

Thanks!