Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NXP-30369: Avoid transaction timeout when computing piture views #4862

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -27,6 +27,7 @@
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentNotFoundException;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.NuxeoException;
import org.nuxeo.ecm.core.api.model.Property;
import org.nuxeo.ecm.core.api.versioning.VersioningService;
import org.nuxeo.ecm.core.event.Event;
Expand All @@ -36,14 +37,15 @@
import org.nuxeo.ecm.platform.picture.api.adapters.PictureResourceAdapter;
import org.nuxeo.ecm.platform.picture.recompute.RecomputeViewsAction;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.transaction.TransactionHelper;

/**
* Work generating the different picture views for a Picture.
*
* @since 5.7
* @deprecated since 11.1 use {@link RecomputeViewsAction} instead
*/
@Deprecated
@Deprecated(since = "11.1")
public class PictureViewsGenerationWork extends AbstractWork {

private static final long serialVersionUID = 1L;
Expand All @@ -52,6 +54,8 @@ public class PictureViewsGenerationWork extends AbstractWork {

public static final String PICTURE_VIEWS_GENERATION_DONE_EVENT = "pictureViewsGenerationDone";

protected static final String NOTHING_TO_PROCESS_MESSAGE = "Nothing to process";

protected final String xpath;

public PictureViewsGenerationWork(String repositoryName, String docId, String xpath) {
Expand Down Expand Up @@ -104,7 +108,7 @@ public void work() {

openSystemSession();
if (!session.exists(new IdRef(docId))) {
setStatus("Nothing to process");
setStatus(NOTHING_TO_PROCESS_MESSAGE);
return;
}

Expand All @@ -120,17 +124,22 @@ public void work() {
setStatus("Generating views");
try {
PictureResourceAdapter picture = workingDocument.getAdapter(PictureResourceAdapter.class);
picture.fillPictureViews(blob, blob.getFilename(), title, null);
TransactionHelper.commitOrRollbackTransaction();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can directly use AbstractWork#commitOrRollbackTransaction.

try {
picture.fillPictureViews(blob, blob.getFilename(), title, null);
} finally {
TransactionHelper.startTransaction();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And AbstractWork#startTransaction(); here.

}
} catch (DocumentNotFoundException e) {
// a parent of the document may have been deleted.
setStatus("Nothing to process");
setStatus(NOTHING_TO_PROCESS_MESSAGE);
return;
} catch (IOException e) {
throw new RuntimeException(e);
throw new NuxeoException(e);
}

if (!session.exists(new IdRef(docId))) {
setStatus("Nothing to process");
setStatus(NOTHING_TO_PROCESS_MESSAGE);
return;
}
setStatus("Saving");
Expand Down
Expand Up @@ -39,6 +39,7 @@
import org.nuxeo.ecm.core.api.DocumentModel;
import org.nuxeo.ecm.core.api.DocumentNotFoundException;
import org.nuxeo.ecm.core.api.IdRef;
import org.nuxeo.ecm.core.api.NuxeoException;
import org.nuxeo.ecm.core.api.model.Property;
import org.nuxeo.ecm.core.bulk.action.computation.AbstractBulkComputation;
import org.nuxeo.ecm.core.bulk.message.BulkCommand;
Expand All @@ -49,6 +50,7 @@
import org.nuxeo.lib.stream.computation.Topology;
import org.nuxeo.runtime.api.Framework;
import org.nuxeo.runtime.stream.StreamProcessorTopology;
import org.nuxeo.runtime.transaction.TransactionHelper;

/**
* BAF Computation that fills picture views for the blob property described by the given xpath.
Expand All @@ -69,9 +71,9 @@ public class RecomputeViewsAction implements StreamProcessorTopology {
@Override
public Topology getTopology(Map<String, String> options) {
return Topology.builder()
.addComputation(RecomputeViewsComputation::new, //
Arrays.asList(INPUT_1 + ":" + ACTION_FULL_NAME, OUTPUT_1 + ":" + STATUS_STREAM))
.build();
.addComputation(RecomputeViewsComputation::new, //
Arrays.asList(INPUT_1 + ":" + ACTION_FULL_NAME, OUTPUT_1 + ":" + STATUS_STREAM))
.build();
}

public static class RecomputeViewsComputation extends AbstractBulkComputation {
Expand Down Expand Up @@ -113,12 +115,17 @@ protected void compute(CoreSession session, List<String> ids, Map<String, Serial
try {
PictureResourceAdapter picture = workingDocument.getAdapter(PictureResourceAdapter.class);
log.debug("Fill picture views for doc: {}", workingDocument);
picture.fillPictureViews(blob, blob.getFilename(), title, null);
TransactionHelper.commitOrRollbackTransaction();
try {
picture.fillPictureViews(blob, blob.getFilename(), title, null);
} finally {
TransactionHelper.startTransaction();
}
} catch (DocumentNotFoundException e) {
// a parent of the document may have been deleted.
continue;
} catch (IOException e) {
throw new RuntimeException(e);
throw new NuxeoException(e);
}

if (workingDocument.isVersion()) {
Expand Down