Skip to content

Commit

Permalink
Increase timeout and add field filter
Browse files Browse the repository at this point in the history
  • Loading branch information
xdnw committed Oct 26, 2024
1 parent 67ed389 commit 8af9cc2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
11 changes: 11 additions & 0 deletions src/main/java/link/locutus/discord/util/sheet/DriveFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
import com.google.api.services.drive.DriveScopes;
import com.google.api.services.drive.model.File;
import com.google.api.services.drive.model.Permission;
import com.google.api.services.drive.model.Revision;
import com.google.api.services.drive.model.RevisionList;
import link.locutus.discord.config.Settings;

import java.io.*;
Expand Down Expand Up @@ -83,6 +85,15 @@ public DriveFile(String fileId) throws GeneralSecurityException, IOException {
this.fileId = fileId;
}

public void purgeVersionHistory() throws IOException {
// List all revisions of the file
RevisionList revisions = service.revisions().list(fileId).execute();
for (Revision revision : revisions.getRevisions()) {
// Delete each revision
service.revisions().delete(fileId, revision.getId()).execute();
}
}

public String getId() {
return fileId;
}
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/link/locutus/discord/util/sheet/SpreadSheet.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,9 +389,9 @@ private static Sheets getServiceAPI() throws GeneralSecurityException, IOExcepti
@Override
public void initialize(final HttpRequest httpRequest) throws IOException {
credentials.initialize(httpRequest);
// httpRequest.setConnectTimeout(10_000);
// httpRequest.setReadTimeout(10_000);
httpRequest.setNumberOfRetries(3);
httpRequest.setConnectTimeout(240_000);
httpRequest.setReadTimeout(240_000);
// httpRequest.setNumberOfRetries(3);
}
};
return new Sheets.Builder(HTTP_TRANSPORT, JSON_FACTORY, credentials)
Expand Down Expand Up @@ -957,27 +957,25 @@ public Map<String, List<List<Object>>> fetchHeaderRows(Set<String> tabNames) {
}

try {
List<String> tabNamesList = new ArrayList<>(tabNames);
// Prepare the ranges for batch request
List<String> ranges = tabNames.stream()
List<String> ranges = tabNamesList.stream()
.map(tab -> tab + "!1:1")
.collect(Collectors.toList());

// Create the batch request
Sheets.Spreadsheets.Values.BatchGet request = service.spreadsheets().values().batchGet(spreadsheetId)
.setRanges(ranges);
.setRanges(ranges)
.setFields("valueRanges.values");

// Execute the batch request
BatchGetValuesResponse response = request.execute();

// Process the response
List<ValueRange> valueRanges = response.getValueRanges();
for (ValueRange valueRange : valueRanges) {
String range = valueRange.getRange();
String tabName = range.split("!")[0];
if (tabName.startsWith("'") && tabName.endsWith("'")) {
tabName = tabName.substring(1, tabName.length() - 1);
}
List<List<Object>> values = valueRange.getValues();
for (int i = 0; i < tabNamesList.size(); i++) {
String tabName = tabNamesList.get(i);
List<List<Object>> values = valueRanges.get(i).getValues();
headers.put(tabName, values != null ? values : Collections.emptyList());
}
} catch (IOException e) {
Expand Down

0 comments on commit 8af9cc2

Please sign in to comment.