From 905081e9fb2fa0cc674cdf2279bce1eb28c640d0 Mon Sep 17 00:00:00 2001 From: Jean Aurambault Date: Mon, 7 Oct 2024 11:29:22 -0700 Subject: [PATCH] Add time measurements in ThirdPartyTMSPhrase --- .../service/thirdparty/ThirdPartyTMSPhrase.java | 15 +++++++++++++-- .../service/thirdparty/phrase/PhraseClient.java | 10 +++++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java index c3211bc94..771f38518 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/ThirdPartyTMSPhrase.java @@ -157,14 +157,17 @@ public void push( final AtomicReference escapeType = getEscapeTypeAtomicReference(nativeClient, optionsParser); + Stopwatch stopwatchGetTextUnitDTO = Stopwatch.createStarted(); List 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(), @@ -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, @@ -214,6 +221,8 @@ public void push( public void removeUnusedKeysAndTags( String projectId, String repositoryName, String tagForUpload) { + Stopwatch stopwatchRemoveUnusedKeysAndTags = Stopwatch.createStarted(); + List tagsForOtherRepositories = phraseClient.listTags(projectId).stream() .map(Tag::getName) @@ -225,7 +234,7 @@ public void removeUnusedKeysAndTags( List allActiveTags = new ArrayList<>(tagsForOtherRepositories); allActiveTags.add(tagForUpload); - logger.info("All active tags: {}", allActiveTags); + logger.debug("All active tags: {}", allActiveTags); phraseClient.removeKeysNotTaggedWith(projectId, allActiveTags); List pushTagsToDelete = @@ -238,6 +247,8 @@ public void removeUnusedKeysAndTags( logger.info("Tags to delete: {}", pushTagsToDelete); phraseClient.deleteTags(projectId, pushTagsToDelete); + + logger.info("removeUnusedKeysAndTags tooks: {}", stopwatchRemoveUnusedKeysAndTags); } private List getSourceTextUnitDTOs( diff --git a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java index f9264726e..71d525954 100644 --- a/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java +++ b/webapp/src/main/java/com/box/l10n/mojito/service/thirdparty/phrase/PhraseClient.java @@ -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; @@ -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)); @@ -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()); @@ -216,6 +220,8 @@ public String nativeUploadCreateFile( List tags, Map 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"; @@ -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();