<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <title>Entity indexation - bulk creation, performance issue</title>
  <link rel="self" href="https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=84923919" />
  <subtitle>Entity indexation - bulk creation, performance issue</subtitle>
  <id>https://liferay.dev/c/message_boards/find_thread?p_l_id=119785294&amp;threadId=84923919</id>
  <updated>2026-05-31T18:00:17Z</updated>
  <dc:date>2026-05-31T18:00:17Z</dc:date>
  <entry>
    <title>RE: Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85144226" />
    <author>
      <name>Jorge Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85144226</id>
    <updated>2017-01-24T20:03:20Z</updated>
    <published>2017-01-24T20:03:20Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;David H Nebinger:&lt;/div&gt;&lt;blockquote&gt;&lt;div class="quote-title"&gt;Jorge Díaz:&lt;/div&gt;&lt;blockquote&gt;All indexation requests are buffered and sent together after database transaction commit&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Except that transactions are wrapped around the addXxxx() methods so this technique will not help you in a batch upload mode.&lt;/blockquote&gt;&lt;br /&gt;I think you can create your own transaction using &lt;strong&gt;TransactionInvokerUtil.invoker&lt;/strong&gt; in same way Staging/LAR does during import task, see:&lt;br /&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="https://github.com/liferay/liferay-portal/blob/master/modules/apps/web-experience/export-import/export-import-service/src/main/java/com/liferay/exportimport/internal/background/task/LayoutImportBackgroundTaskExecutor.java#L84-L86"&gt;https://github.com/liferay/liferay-portal/blob/master/modules/apps/web-experience/export-import/export-import-service/src/main/java/com/liferay/exportimport/internal/background/task/LayoutImportBackgroundTaskExecutor.java#L84-L86&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;TransactionInvokerUtil.invoker will create a new database transaction if you are outside of any and will execute inside of it the call method of the callable class.&lt;br /&gt;For &lt;em&gt;LayoutImportBackgroundTaskExecutor &lt;/em&gt;example, it will execute &amp;#34;call&amp;#34; method of the inner class &lt;em&gt;LayoutImportBackgroundTaskExecutor.LayoutImportCallable&lt;/em&gt;&lt;br /&gt;&lt;br /&gt;You can also create a &amp;#34;dummy&amp;#34; service builder project in order to create a *ServiceImpl class with transactional method and add all the logic there, see: &lt;ul&gt;&lt;li&gt;&lt;a href="http://www.xtivia.com/handling-transactions-across-multiple-liferay-api-calls/"&gt;http://www.xtivia.com/handling-transactions-across-multiple-liferay-api-calls/&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;But I think it is better to follow the Staging/LAR approach and call &lt;strong&gt;TransactionInvokerUtil.invoker&lt;/strong&gt;</summary>
    <dc:creator>Jorge Diaz</dc:creator>
    <dc:date>2017-01-24T20:03:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85109671" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85109671</id>
    <updated>2017-01-24T05:09:39Z</updated>
    <published>2017-01-24T05:09:39Z</published>
    <summary type="html">&lt;div class="quote-title"&gt;Jorge Díaz:&lt;/div&gt;&lt;blockquote&gt;All indexation requests are buffered and sent together after database transaction commit&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;Except that transactions are wrapped around the addXxxx() methods so this technique will not help you in a batch upload mode.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2017-01-24T05:09:39Z</dc:date>
  </entry>
  <entry>
    <title>RE: Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85026790" />
    <author>
      <name>Jorge Diaz</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=85026790</id>
    <updated>2017-01-20T21:32:20Z</updated>
    <published>2017-01-20T21:32:20Z</published>
    <summary type="html">Hi Eric,&lt;br /&gt;&lt;br /&gt;&lt;div class="quote-title"&gt;Eric COQUELIN:&lt;/div&gt;&lt;blockquote&gt;Thanks for replying so quickly.&lt;br /&gt;&lt;br /&gt;To be honnest, I wished there was an OOTB solution but it looks like we need workaround.&lt;/blockquote&gt;&lt;br /&gt;&lt;br /&gt;In 7.0/DXP that functionality is implemented in &lt;a href="https://issues.liferay.com/browse/LPS-56593"&gt;LPS-56593&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;All indexation requests are buffered and sent together after database transaction commit</summary>
    <dc:creator>Jorge Diaz</dc:creator>
    <dc:date>2017-01-20T21:32:20Z</dc:date>
  </entry>
  <entry>
    <title>RE: Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84940660" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84940660</id>
    <updated>2017-01-18T20:11:12Z</updated>
    <published>2017-01-18T20:11:12Z</published>
    <summary type="html">Thanks for replying so quickly.&lt;br /&gt;&lt;br /&gt;To be honnest, I wished there was an OOTB solution but it looks like we need workaround.&lt;br /&gt;&lt;br /&gt;Thank you again.</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2017-01-18T20:11:12Z</dc:date>
  </entry>
  <entry>
    <title>RE: Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84933546" />
    <author>
      <name>David H Nebinger</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84933546</id>
    <updated>2017-01-18T16:29:30Z</updated>
    <published>2017-01-18T16:29:30Z</published>
    <summary type="html">Actually I think this should all be possible...&lt;br /&gt;&lt;br /&gt;So say in your entity service impl you add a local boolean field, &amp;#34;indexing&amp;#34; and add appropriate getter/setter.  This becomes your flag as to whether to actually index or not.&lt;br /&gt;&lt;br /&gt;Your bulk process would disable indexing, do the bulk load as-is, then enable indexing.&lt;br /&gt;&lt;br /&gt;I&amp;#39;d actually add code to the setter that, when you are enabling the indexing, have it invoke the same reindexing as the control panel&amp;#39;s individual indexing option (starts the background thread to reindex all entities).&lt;br /&gt;&lt;br /&gt;Your indexer class, well that should have access to the service layer so every time it is asked to index a doc, you check the enabled flag and, if not enabled, just return null (a return of null effectively means &amp;#34;nothing here to index&amp;#34;).&lt;br /&gt;&lt;br /&gt;This should allow you to delay indexing of this entity type until the bulk load is complete and reindex afterwards, but you must remember that you will be consuming a lot of time reindexing all of the entities.  Rather than reindexing all entities, you might want to keep track of the added ids during the bulk load and, after reenabling indexing, manually reindex the added/updated entities individually.&lt;br /&gt;&lt;br /&gt;Best I can offer, there really isn&amp;#39;t a way to OOTB disable individual indexers that wouldn&amp;#39;t require a lot of other invasive changes to the core.</summary>
    <dc:creator>David H Nebinger</dc:creator>
    <dc:date>2017-01-18T16:29:30Z</dc:date>
  </entry>
  <entry>
    <title>Entity indexation - bulk creation, performance issue</title>
    <link rel="alternate" href="https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84923918" />
    <author>
      <name>Eric COQUELIN</name>
    </author>
    <id>https://liferay.dev/c/message_boards/find_message?p_l_id=119785294&amp;messageId=84923918</id>
    <updated>2017-01-18T13:05:07Z</updated>
    <published>2017-01-18T13:05:07Z</published>
    <summary type="html">&lt;html&gt;&lt;head&gt;&lt;/head&gt;&lt;body&gt;Dear all,&lt;br&gt;&lt;br&gt;I have created a new entity&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;entity name="TaxFormField" local-service="true" remote-service="false" uuid="true"&amp;gt;

		&amp;lt;!-- PK fields --&amp;gt;
		&amp;lt;column name="taxFormFieldId" type="long" primary="true"&amp;gt;&amp;lt;/column&amp;gt;

		...

		&amp;lt;reference package-path="com.liferay.portlet.asset" entity="AssetEntry" /&amp;gt;

	&amp;lt;/entity&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;Then, I have implemented a bulk creation module to load about 10k lines from a file which corresponds each to an instance of the entity. Using the same transaction, I call the add method&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;public TaxFormField addTaxFormField(TaxFormField taxFormField, ServiceContext serviceContext) throws PortalException, SystemException {

		taxFormField.setGroupId(serviceContext.getScopeGroupId());
		taxFormField.setCompanyId(serviceContext.getCompanyId());
		taxFormField.setCreateDate(serviceContext.getCreateDate(new Date()));
		taxFormField.setStatus(WorkflowConstants.STATUS_DRAFT);

...

		taxFormField = this.addTaxFormField(taxFormField);
		return taxFormField;
	}&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;which calls itself the default generated method&lt;br&gt;&lt;pre&gt;&lt;code&gt;taxFormField = this.addTaxFormField(taxFormField);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;That method has annotation for indexation&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;@Indexable(type = IndexableType.REINDEX)&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;As i have defined a specific indexer for this entity in my XML file, it calls reindex each time an entity is added&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;&amp;lt;indexer-class&amp;gt;com.xxx.yyy.tax.indexer.TaxFormFieldIndexer&amp;lt;/indexer-class&amp;gt;&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;As a result, file loading takes an eternity to complete... I wish I could:&lt;br&gt;&lt;ul&gt;&lt;li&gt;bulk index once the file is loaded - that is possible but it continues indexing for each entity being added&lt;/li&gt;&lt;li&gt;optimize entity indexation so that it uses same transaction and commit only once&lt;/li&gt;&lt;/ul&gt;&lt;br&gt;&lt;br&gt;I have no idea how to achieve second point so I opted for the first one. &lt;br&gt;&lt;br&gt;However, calling directly the persistence method, which is not annoted with @indexable, triggers the listeners...&lt;br&gt;&lt;br&gt;&lt;pre&gt;&lt;code&gt;taxFormFieldPersistence.update(taxFormField);&lt;/code&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;And the problem remains as it looks like there is an indexer listener.&lt;br&gt;&lt;br&gt;How can I optimize the indexation of entity while bulk loading?&lt;br&gt;&lt;br&gt;Thank you in advance for your help.&lt;/body&gt;&lt;/html&gt;</summary>
    <dc:creator>Eric COQUELIN</dc:creator>
    <dc:date>2017-01-18T13:05:07Z</dc:date>
  </entry>
</feed>
