Skip to content

Commit

Permalink
Calculate scheduler limits for sync using AnkiWeb limit
Browse files Browse the repository at this point in the history
Fixes #5666 - Sync Failure on Large Dynamic Decks

We modified `mReportLimit` in #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 authored and mikehardy committed Mar 26, 2020
1 parent f8123f1 commit b06592e
Show file tree
Hide file tree
Showing 4 changed files with 51 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 @@ -2124,4 +2124,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;
}
}
14 changes: 14 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/Sched.java
Original file line number Diff line number Diff line change
Expand Up @@ -2486,6 +2486,20 @@ public boolean leechActionSuspend(Card card) {
}
}

/** not in libAnki. Added due to #5666: inconsistent selected deck card counts on sync */
public int[] recalculateCounts() {
_resetLrnCount();
_resetNewCount();
_resetRevCount();
return new int[] { mNewCount, mLrnCount, mRevCount };
}

public void setReportLimit(int reportLimit) {
this.mReportLimit = reportLimit;
}

/** End #5666 */


public void setContext(WeakReference<Activity> contextReference) {
mContextReference = contextReference;
Expand Down
15 changes: 15 additions & 0 deletions AnkiDroid/src/main/java/com/ichi2/libanki/SchedV2.java
Original file line number Diff line number Diff line change
Expand Up @@ -2744,4 +2744,19 @@ public void setContext(WeakReference<Activity> contextReference) {
mContextReference = contextReference;
}

/** not in libAnki. Added due to #5666: inconsistent selected deck card counts on sync */
@Override
public int[] recalculateCounts() {
_resetLrnCount();
_resetNewCount();
_resetRevCount();
return new int[] { mNewCount, mLrnCount, mRevCount };
}

@Override
public void setReportLimit(int reportLimit) {
this.mReportLimit = reportLimit;
}

/** End #5666 */
}
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 b06592e

Please sign in to comment.