Anki-android: Anki2.1 - support dynamic ankiweb sync URL

Created on 28 Aug 2018  路  12Comments  路  Source: ankidroid/Anki-Android

Anki2.1 appears to have implemented a dynamic URL for syncing, with user profiles storing a "hostNum" used to dynamically create the URL to use for syncing:

Pulling hostNum from profile:
https://github.com/dae/anki/blob/master/aqt/sync.py#L47

Patch with the change:
https://github.com/dae/anki/commit/ae46bfa8d18778a7312828c3fd9b8d6c6e4672d6#diff-be58d55ab11f38bc77a9e44496f1d2a8

This may help @dae manage server load better (though any comments from him would be welcome!), but the current URLs still work so is not a breaking change

Accepted Anki Ecosystem Compatibility Enhancement Help Wanted Priority-Low

All 12 comments

Yes, it would be great if this could be ported when someone gets a chance.

Thanks for replying. Okay, it seems my understanding isn't too far off then. Can we expect server side to handle hostNum, send it in the meta response on login/auth, and we should just use it if there for the rest of the syncing, and fallback to the base URL if not? And I don't think it was persistent on the client, is that correct? So it could vary per Auth response?

Hi Mike,

The server will provide hostNum in the /sync/meta call. All requests after that (including future meta requests) should use that hostNum to construct the sync URL, until a future /sync/meta call advises otherwise. To ensure hostNum is used with future meta requests, AD will need to persist the value.

If you decide to tackle this, it may be worth looking into https://github.com/ankidroid/Anki-Android/issues/4568 at the same time.

@dae

Out of interest why not just handle load balancing on server (proxy) side?

Interesting, thanks for clarifying. And I hadn't seen #4568 yet - that seems like an easy win.

Our current sync code is a bit of a mess, I'm not sure if changing any of it will be "easy", also see #3626

Currently the traffic is proxied with round robin DNS, but it is more efficient for the client to communicate with the correct server directly than to use up the limited network bandwidth proxying traffic to another server.

@dae - while I have your ear - I saw the dynamic URL, the v2 scheduler, and mathjax as the major changes Anki just implemented (with profile support and latex being older ones unimplemented in AnkiDroid). Even though it seems the most complicated, it seems like scheduler v2 support is the most important in the near-term as switching back and forth seems like trouble for the users. But you may think differently, and I'm curious if that's so.

It needs to be done at one point, but it's a fair amount of work and needs to be done carefully to avoid introducing bugs - you might want to work on MathJax first, which is simpler.

@dae, I'm working on this and have a couple of questions that I hope you could lend a hand with

Firstly,

  • Does the hostKey method support a hostNum?

Secondly, I believe the two branches of the following code are legacy and can be removed, is this the case:

  • upgrade is replaced with upload: be546458462ce5ec7cf985e6b7d955e6655dfdf9

  • register replaced with hostKey

https://github.com/ankidroid/Anki-Android/blob/ab8f492e079ed6f01c6ab6aac8cbfb2030bb51d1/AnkiDroid/src/main/java/com/ichi2/libanki/sync/HttpSyncer.java#L184-L192

Thanks for your time,

In the logged out state, we don't know which host the user is on, so hostNum should be null. It could potentially return the hostNum, but it doesn't as it needs to be checked by meta anyway, as users may be migrated between servers.

Those two endpoints look like they could be removed. Upgrade was an old endpoint that upgraded Anki 1.x collections, and users need to sign up for an account in a webview these days.

released as 2.10alpha70 as soon as google finishes processing it

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mashinbaz1 picture mashinbaz1  路  6Comments

littlefoodt picture littlefoodt  路  4Comments

snowtimeglass picture snowtimeglass  路  5Comments

david-allison-1 picture david-allison-1  路  4Comments

hanpingchinese picture hanpingchinese  路  5Comments