Skip to content

Commit

Permalink
feat: Add SQLHandler.setPageSize
Browse files Browse the repository at this point in the history
Allows setting the page size from a reference to the backend
  • Loading branch information
david-allison committed Apr 3, 2021
1 parent 03a9d6b commit ea04e0e
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public void before() {
} catch (RustBackendFailedException e) {
throw new RuntimeException(e);
}
BackendV1Impl.setPageSize(TEST_PAGE_SIZE);
BackendV1Impl.setPageSizeForTesting(TEST_PAGE_SIZE);
}

@After
Expand Down
10 changes: 10 additions & 0 deletions rsdroid/src/main/java/net/ankiweb/rsdroid/BackendMutex.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion rsdroid/src/main/java/net/ankiweb/rsdroid/BackendV1Impl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions rsdroid/src/main/java/net/ankiweb/rsdroid/database/SQLHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,11 @@ public void cancelAllProtoQueries() {
backend.cancelAllProtoQueries();
}

@Override
public void setPageSize(long pageSizeBytes) {
backend.setPageSize(pageSizeBytes);
}


public void setTransactionSuccessful() {
if (!inTransaction()) {
Expand Down

0 comments on commit ea04e0e

Please sign in to comment.