davidsansome / tsurukame

Tsurukame is an unofficial WaniKani app for iOS. It helps you learn Japanese Kanji.
https://tsurukame.app
Apache License 2.0
262 stars 61 forks source link

Reviews are not working #277

Open ghost opened 4 years ago

ghost commented 4 years ago

Hello! First of all I want to thank you fot this amazing app...It's really useful and user-friendly and it really helped me to get my lessons and reviews in order...but a month ago it stopped working for me. And it's a shame because I think it's the best app in the App Store for wanikani :(

It seems that the app cannot submit my lessons and reviews...If I do some reviews and go to the PC I see the reviews from my app weren't submitted so I have to do them again. Also, if I go to Show remaining section all the cards are blank...so it clearly can connect to wanikani.

My device is an iPhone 7. I tried to uninstall and install again but it didn't solve anything.

Some help please, I'm stuck a level 19 forever because I hardly can go to a pc to do my reviews and other apps are terrible :(

ghost commented 4 years ago

Don't know If it's okay to comment here or in the other issue...

How can I test it?

UInt2048 commented 4 years ago

@alisonlopez, Do you experience this issue on the official TestFlight? To test it, you could click the link in the README and do reviews (use the wrap up to do like 5) then see if the count goes down after refreshing in the other Tsurukame you have from the App Store.

mzsanford commented 4 years ago

@alisonlopez if you have a Mac check out https://github.com/davidsansome/tsurukame/issues/235#issuecomment-577273703 for how to gather logs that can help us find the root cause and get it fixed.

ghost commented 4 years ago

Yeah, It doesn't work even with the testflight app.

Sorry I don't have a MAC to get the logs for you :(

davidsansome commented 4 years ago

@alisonlopez could you go to Settings in the app, hit "Export local database" at the bottom and email it to me@davidsansome.com? That should contain a log of the requests that failed.

UInt2048 commented 4 years ago

@davidsansome Dupe of #177

davidsansome commented 4 years ago

@alisonlopez sent me their database, it looks like there's a clock skew problem on the client:

sqlite> select request_url, response_data from error_log;
https://api.wanikani.com/v2/assignments?unlocked=true&hidden=false&updated_after=2020-01-22T20:53:54.486000Z|{"error":"The updated_after parameter must be in the past","code":422}
https://api.wanikani.com/v2/study_materials?updated_after=2020-01-22T20:53:52.563000Z|{"error":"The updated_after parameter must be in the past","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/assignments?unlocked=true&hidden=false&updated_after=2020-01-22T20:54:14.676000Z|{"error":"The updated_after parameter must be in the past","code":422}
https://api.wanikani.com/v2/study_materials?updated_after=2020-01-22T20:54:14.605000Z|{"error":"The updated_after parameter must be in the past","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/reviews/|{"error":"Record invalid","code":422}
https://api.wanikani.com/v2/assignments?unlocked=true&hidden=false&updated_after=2020-01-23T08:54:24.697000Z|{"error":"The updated_after parameter must be in the past","code":422}
https://api.wanikani.com/v2/study_materials?updated_after=2020-01-23T08:54:25.032000Z|{"error":"The updated_after parameter must be in the past","code":422}

Requests for assignments and study materials are being made with timestamps in the future (from the server's perspective), so are being rejected. Review progress requests are also being rejected for "Record invalid", probably because their created_at date is in the future.

We don't retry requests that get a 422 response because it often means the review has been done on another device (and retrying won't help): https://github.com/davidsansome/tsurukame/blob/master/ios/LocalCachingClient.mm#L843

So there are a few bugs here:

  1. When fetching assignments or study materials we set the assignments_updated_after and study_materials_updated_after to the Client's time, rather than the server time. We should use the data_updated_at field in the server response so we use the Server's time.
  2. We shouldn't set the created_at date on reviews that have been created in the last hour - if we omit it the server will use its current time, and setting it only matters for reviews that have been done while the device was offline, and enough time should have passed since then to counter the clock skew.
  3. If a progress request fails with 422 we could retry it once without the created_at field.