Optimizing Object Managers for Batch Processing

1C Developer team

19.11.2024 5 min

Optimizing Object Managers for Batch Processing

When analyzing the code of existing standard configurations, we found that batch processing of database objects (catalogs, documents, etc.) is quite often performed according to a given set of references to objects. During processing, the state of each object is loaded from the database using Reference.GetObject(). Then, the values of the attributes are analyzed and, if necessary, the object is modified and written.

Each of the Reference.GetObject() operations results in a database call to read the object's state, which is quite expensive. At the same time, the 1C:Enterprise platform has had a selection mechanism since version 8.0, which allows you to get a selection containing data from many objects at once with a single database call.

We have also repeatedly received requests from developers using our technologies to speed up mass operations with objects.

To enable faster batch processing, in platform version 8.3.26, we have implemented the SelectByRefs() method in the database object managers, which allows you to retrieve selections based on a given set of references.

The following object managers now include the SelectByRefs(<Source>, <Column>) method: CatalogManager.<Catalog_Name>, DocumentManager.<Document_Name>, ChartOfCharacteristicTypesManager.<ChartOfCharacteristicTypes_Name>, etc. (a complete list will be available in the documentation).

The SelectByRefs() method is generally similar to the Select() method, which is present in one form or another in each of the mentioned managers. Both methods return a selection of objects of the respective type. The difference is that SelectByRefs() receives a collection of references to objects of the type corresponding to the manager as a selection criterion.

Here are the parameters of the SelectByRefs() method: 

    <Source> (required): The source of references to objects. This can be a ValueTable, QueryResult, Array, or FixedArray.

    <Column> (optional): If the value of the first parameter is a ValueTable or QueryResult, then this parameter can be used to specify the column containing the references. The column can be specified by name (a value of type String) or by index (a value of type Number). If the parameter value is not specified, the first column of the source is used. If the value of the <Source> parameter is an Array, then the value of the <Column> parameter is ignored.

The method returns a selection of objects of the type corresponding to the manager: CatalogSelection.<Catalog_Name>, DocumentSelection.<Document_Name>, etc.

The SelectByRefs() method reads objects in batches (as does the Select() method). Note that this mechanism does not provide consistent reading unless additional measures are taken. For example, if a product is moved from one order to another in some operation, a situation may arise where the product ends up in two orders, since one is counted before the data transfer and the other after. In other words, data consistency is ensured only at the level of individual objects, but not the entire selection as a whole.

Here is an example of usage:

code opt1.png

We recommend that developers consider using the SelectByRefs(<Source>, <Column>) methods for mass processing of objects by a set of references to improve performance, which can be especially important for large deployments.

Be the first to know tips & tricks on business application development!

A confirmation e-mail has been sent to the e-mail address you provided .

Click the link in the e-mail to confirm and activate the subscription.