Skip to content

Commit

Permalink
Add time measurements in ThirdPartyTMSPhrase
Browse files Browse the repository at this point in the history
  • Loading branch information
ja-openai committed Oct 8, 2024
1 parent 5636e5f commit 1363982
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,14 +157,17 @@ public void push(
final AtomicReference<EscapeType> escapeType =
getEscapeTypeAtomicReference(nativeClient, optionsParser);

Stopwatch stopwatchGetTextUnitDTO = Stopwatch.createStarted();
List<TextUnitDTO> search =
getSourceTextUnitDTOs(repository, skipTextUnitsWithPattern, skipAssetsWithPathPattern);
logger.info("Get Source TextUnitDTO for push took: {}", stopwatchGetTextUnitDTO.elapsed());
String text = getFileContent(pluralSeparator, search, true, null, escapeType.get());

String tagForUpload = getTagForUpload(repository.getName());

if (nativeClient) {
logger.info("Pushing with native and options: {}", formatOptions);
logger.debug("Pushing with native and options: {}", formatOptions);
Stopwatch stopWatchPhaseNativePush = Stopwatch.createStarted();
phraseClient.nativeUploadAndWait(
projectId,
repository.getSourceLocale().getBcp47Tag(),
Expand All @@ -173,6 +176,10 @@ public void push(
text,
ImmutableList.of(tagForUpload),
formatOptions.isEmpty() ? null : formatOptions);
logger.info(
"Pushing with native and options: {}, took: {}",
formatOptions,
stopWatchPhaseNativePush.elapsed());
} else {
phraseClient.uploadAndWait(
projectId,
Expand Down Expand Up @@ -214,6 +221,8 @@ public void push(
public void removeUnusedKeysAndTags(
String projectId, String repositoryName, String tagForUpload) {

Stopwatch stopwatchRemoveUnusedKeysAndTags = Stopwatch.createStarted();

List<String> tagsForOtherRepositories =
phraseClient.listTags(projectId).stream()
.map(Tag::getName)
Expand All @@ -225,7 +234,7 @@ public void removeUnusedKeysAndTags(
List<String> allActiveTags = new ArrayList<>(tagsForOtherRepositories);
allActiveTags.add(tagForUpload);

logger.info("All active tags: {}", allActiveTags);
logger.debug("All active tags: {}", allActiveTags);
phraseClient.removeKeysNotTaggedWith(projectId, allActiveTags);

List<String> pushTagsToDelete =
Expand All @@ -238,6 +247,8 @@ public void removeUnusedKeysAndTags(

logger.info("Tags to delete: {}", pushTagsToDelete);
phraseClient.deleteTags(projectId, pushTagsToDelete);

logger.info("removeUnusedKeysAndTags tooks: {}", stopwatchRemoveUnusedKeysAndTags);
}

private List<TextUnitDTO> getSourceTextUnitDTOs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import com.box.l10n.mojito.json.ObjectMapper;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Stopwatch;
import com.google.common.collect.ImmutableSet;
import com.phrase.client.ApiClient;
import com.phrase.client.ApiException;
Expand Down Expand Up @@ -92,10 +93,11 @@ public Upload uploadAndWait(

Upload waitForUploadToFinish(String projectId, String uploadId) {
UploadsApi uploadsApi = new UploadsApi(apiClient);

try {
logger.debug("Waiting for upload to finish: {}", uploadId);

Stopwatch stopwatch = Stopwatch.createStarted();

Upload upload = uploadsApi.uploadShow(projectId, uploadId, null, null);
logger.debug(
"Upload info, first fetch: {}", new ObjectMapper().writeValueAsStringUnchecked(upload));
Expand All @@ -117,6 +119,8 @@ Upload waitForUploadToFinish(String projectId, String uploadId) {
"Upload failed: %s".formatted(new ObjectMapper().writeValueAsStringUnchecked(upload)));
}

logger.info("Waited: {} for upload: {} to finish", stopwatch.elapsed(), uploadId);

return upload;
} catch (ApiException e) {
logger.error("Error calling Phrase for waitForUploadToFinish: {}", e.getResponseBody());
Expand Down Expand Up @@ -216,6 +220,8 @@ public String nativeUploadCreateFile(
List<String> tags,
Map<String, String> formatOptions) {

Stopwatch stopwatch = Stopwatch.createStarted();

String urlString = String.format("%s/projects/%s/uploads", apiClient.getBasePath(), projectId);
String boundary = UUID.randomUUID().toString();
final String LINE_FEED = "\r\n";
Expand Down Expand Up @@ -269,6 +275,8 @@ public String nativeUploadCreateFile(
throw new RuntimeException(e);
}

logger.info("nativeUploadCreateFile took: {}", stopwatch.elapsed());

int statusCode = response.statusCode();
String responseBody = response.body();

Expand Down

0 comments on commit 1363982

Please sign in to comment.