Skip to content

Commit

Permalink
Fix ankidroid#5666 - Sync Failure on Large Dynamic Decks
Browse files Browse the repository at this point in the history
We modified `mReportLimit` in ankidroid#5326 to allow a user to see how many
cards they had if there were more than 1000 in a queue.

This had an impact on calculating the number of cards in the current
deck, which is required for a sync to ensure that the server and client
are consistent.

This caused an inconsistency (as we calculate the proper value), and
this meant that a full sync needed to occur if a dynamic deck with over
1000 cards in a queue was selected.

This fixes it by using a new scheduler with the correct `mReportLimit`
for calculating the number of cards in the selected deck
  • Loading branch information
david-allison committed Mar 24, 2020
1 parent a2f8c09 commit 7f5171e
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
13 changes: 13 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Collection.java
Original file line number Diff line number Diff line change
Expand Up @@ -2022,4 +2022,17 @@ public Context getContext() {
return mContext;
}

/** Not in libAnki */

//This duplicates _loadScheduler (but returns the value and sets the report limit).
public Sched createScheduler(int reportLimit) {
int ver = schedVer();
if (ver == 1) {
mSched = new Sched(this);
} else if (ver == 2) {
mSched = new SchedV2(this);
}
mSched.setReportLimit(reportLimit);
return mSched;
}
}
13 changes: 13 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Sched.java
Original file line number Diff line number Diff line change
Expand Up @@ -2538,6 +2538,19 @@ public boolean leechActionSuspend(Card card) {
}
}

//not in libAnki. Added due to #5666 (
public int[] recalculateCounts() {
_resetLrnCount();
_resetNewCount();
_resetRevCount();
return new int[] { mNewCount, mLrnCount, mRevCount };
}

//not in libAnki. Added due to #5666 (
public void setReportLimit(int reportLimit) {
this.mReportLimit = reportLimit;
}


public void setContext(WeakReference<Activity> contextReference) {
mContextReference = contextReference;
Expand Down
10 changes: 9 additions & 1 deletion AnkiDroid/src/main/java/com/ichi2/libanki/sync/Syncer.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.ichi2.async.Connection;
import com.ichi2.libanki.Collection;
import com.ichi2.libanki.Consts;
import com.ichi2.libanki.Sched;
import com.ichi2.libanki.Utils;

import org.json.JSONArray;
Expand Down Expand Up @@ -57,6 +58,9 @@ public class Syncer {
public static final int TYPE_STRING = 3;
public static final int TYPE_BLOB = 4;

/** The libAnki value of `sched.mReportLimit` */
private static final int SYNC_SCHEDULER_REPORT_LIMIT = 1000;

private Collection mCol;
private HttpSyncer mServer;
private long mRMod;
Expand Down Expand Up @@ -377,7 +381,11 @@ public JSONObject sanityCheck() {
// return summary of deck
JSONArray ja = new JSONArray();
JSONArray sa = new JSONArray();
for (int c : mCol.getSched().counts()) {

//#5666 - not in libAnki
//We modified mReportLimit inside the scheduler, and this causes issues syncing dynamic decks.
Sched syncScheduler = mCol.createScheduler(SYNC_SCHEDULER_REPORT_LIMIT);
for (int c : syncScheduler.recalculateCounts()) {
sa.put(c);
}
ja.put(sa);
Expand Down

0 comments on commit 7f5171e

Please sign in to comment.