diff --git a/rsdroid-instrumented/src/androidTest/java/net/ankiweb/rsdroid/ankiutil/InstrumentedTest.java b/rsdroid-instrumented/src/androidTest/java/net/ankiweb/rsdroid/ankiutil/InstrumentedTest.java index ddaf62935..9e33bca9d 100644 --- a/rsdroid-instrumented/src/androidTest/java/net/ankiweb/rsdroid/ankiutil/InstrumentedTest.java +++ b/rsdroid-instrumented/src/androidTest/java/net/ankiweb/rsdroid/ankiutil/InstrumentedTest.java @@ -59,7 +59,7 @@ public void before() { } catch (RustBackendFailedException e) { throw new RuntimeException(e); } - BackendV1Impl.setPageSize(1000); + BackendV1Impl.setPageSizeForTesting(1000); } @After diff --git a/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendMutex.java b/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendMutex.java index 6f48c9701..665c6d9df 100644 --- a/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendMutex.java +++ b/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendMutex.java @@ -178,6 +178,16 @@ public void cancelAllProtoQueries() { } } + @Override + public void setPageSize(long pageSizeBytes) { + try { + lock.lock(); + backend.setPageSize(pageSizeBytes); + } finally { + lock.unlock(); + } + } + // RustBackend Implementation @Override diff --git a/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendV1Impl.java b/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendV1Impl.java index 714f98a11..d31bc870f 100644 --- a/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendV1Impl.java +++ b/rsdroid/src/main/java/net/ankiweb/rsdroid/BackendV1Impl.java @@ -342,11 +342,15 @@ private void performTransaction(String kind) { } @VisibleForTesting(otherwise = VisibleForTesting.NONE) - public static void setPageSize(long pageSizeInBytes) { + public static void setPageSizeForTesting(long pageSizeInBytes) { // TODO: Make this nonstatic NativeMethods.setDbPageSize(pageSizeInBytes); } + @Override + public void setPageSize(long pageSizeInBytes) { + NativeMethods.setDbPageSize(pageSizeInBytes); + } @Override public String[] getColumnNames(String sql) { diff --git a/rsdroid/src/main/java/net/ankiweb/rsdroid/database/SQLHandler.java b/rsdroid/src/main/java/net/ankiweb/rsdroid/database/SQLHandler.java index 3b7263591..f0e8c8496 100644 --- a/rsdroid/src/main/java/net/ankiweb/rsdroid/database/SQLHandler.java +++ b/rsdroid/src/main/java/net/ankiweb/rsdroid/database/SQLHandler.java @@ -46,4 +46,14 @@ public interface SQLHandler { void cancelCurrentProtoQuery(int sequenceNumber); void cancelAllProtoQueries(); + + /** + * Sets the page size for all future calls to + * {@link SQLHandler#getNextSlice(long, int)} + * and + * {@link SQLHandler#fullQueryProto(String, Object...)} + * + * Default: 2MB + */ + void setPageSize(long pageSizeBytes); } diff --git a/rsdroid/src/main/java/net/ankiweb/rsdroid/database/Session.java b/rsdroid/src/main/java/net/ankiweb/rsdroid/database/Session.java index 4ff017ce0..985ba65a6 100644 --- a/rsdroid/src/main/java/net/ankiweb/rsdroid/database/Session.java +++ b/rsdroid/src/main/java/net/ankiweb/rsdroid/database/Session.java @@ -105,6 +105,11 @@ public void cancelAllProtoQueries() { backend.cancelAllProtoQueries(); } + @Override + public void setPageSize(long pageSizeBytes) { + backend.setPageSize(pageSizeBytes); + } + public void setTransactionSuccessful() { if (!inTransaction()) {