Skip to content

Commit

Permalink
Merge pull request #6554 from seadowg/form-size-logging
Browse files Browse the repository at this point in the history
Log form and CSV instance sizes when loading
  • Loading branch information
lognaturel authored Dec 19, 2024
2 parents 1fdc79f + 0b52f51 commit c427388
Showing 1 changed file with 32 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import java.io.FileFilter;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

Expand Down Expand Up @@ -192,6 +193,8 @@ protected FECWrapper doInBackground(Void... ignored) {
unzipMediaFiles(formMediaDir);
setupReferenceManagerForForm(ReferenceManager.instance(), formMediaDir);

logFormDetails(formXml, formMediaDir);

FormDef formDef = null;
try {
formDef = createFormDefFromCacheOrXml(form.getFormFilePath(), formXml);
Expand Down Expand Up @@ -276,6 +279,35 @@ protected FECWrapper doInBackground(Void... ignored) {
return data;
}

private void logFormDetails(File formFile, File formMediaDir) {
long formFileBytesSize = formFile.length();

List<String> csvFileBytesSizes = new ArrayList<>();
File[] files = formMediaDir.listFiles();
if (files != null) {
for (File mediaFile : files) {
if (mediaFile.getName().endsWith(".csv")) {
csvFileBytesSizes.add(mediaFile.length() + "B");
}
}
}

if (csvFileBytesSizes.isEmpty()) {
Timber.w(
"Attempting to load from %s, file is %dB",
formFile.getAbsolutePath(),
formFileBytesSize
);
} else {
Timber.w(
"Attempting to load from %s, file is %dB and has CSV files %s",
formFile.getAbsolutePath(),
formFileBytesSize,
String.join(", ", csvFileBytesSizes)
);
}
}

private static void unzipMediaFiles(File formMediaDir) {
File[] zipFiles = formMediaDir.listFiles(new FileFilter() {
@Override
Expand Down Expand Up @@ -305,7 +337,6 @@ private FormDef createFormDefFromCacheOrXml(String formPath, File formXml) throw
}

// no binary, read from xml
Timber.i("Attempting to load from: %s", formXml.getAbsolutePath());
final long start = System.currentTimeMillis();
String lastSavedSrc = FileUtils.getOrCreateLastSavedSrc(formXml);
FormDef formDefFromXml = XFormUtils.getFormFromFormXml(formPath, lastSavedSrc);
Expand Down

0 comments on commit c427388

Please sign in to comment.