Skip to content

BSL217 — Missing temporary storage data deletion after using

Summary

Missing temporary storage data deletion after using

Identifiers

Field Value
Rule code BSL217
Compatible alias MissingTempStorageDeletion
Severity WARNING
Enabled by default Yes
Implemented Yes
Tags resource-management, memory

Behavior

  • The public identifier BSL217 and alias MissingTempStorageDeletion are stable.
  • The rule reports the cases documented on this page.
  • Suppressions and project configuration are applied before publication.
  • The rule requires neither an external analyzer nor network access.

Configuration and suppression

BSL### is the primary stable identifier. The compatible alias is accepted in select, ignore, and compatible block suppression comments.

[tool.onec-hbk-bsl]
select = ["BSL217"]
ignore = ["MissingTempStorageDeletion"]

All three suppression families support both a current line and a range. When an opening comment follows code, it affects only that line. Use any one form:

  • noqa:
Value = "example";  // noqa: BSL217
  • bsl-disable:
Value = "example";  // bsl-disable: BSL217
  • compatible BSLLS form:
Value = "example";  // BSLLS:MissingTempStorageDeletion-off

When the same opening comment is on a line by itself, it starts a range. Close it with the matching marker from the same family:

// noqa: BSL217
// code without this diagnostic
// noqa-enable: BSL217

// bsl-disable: BSL217
// code without this diagnostic
// bsl-enable: BSL217

// BSLLS:MissingTempStorageDeletion-off
// code without this diagnostic
// BSLLS:MissingTempStorageDeletion-on

To disable the rule until the end of the file, omit the closing noqa-enable, bsl-enable, or BSLLS:…-on marker.

Opening and closing markers must belong to the same family.

Description

Отсутствует удаление данных из временного хранилища после использования (MissingTempStorageDeletion)

Type Scope Severity Activated by default Minutes
to fix
Tags
Code smell BSL
OS
Critical No 3 standard
performance
badpractice

Diagnostics description

Diagnostics is now tracking all GetFromTempStorage calls that do not have a corresponding DeleteFromTempStorage call - within one method!

The rules for working with objects in temporary storage are often violated - storing data in it is not free. There are errors even in the documentation and numerous use cases.

When placing data in temporary storage, you should choose one of two options:

  • put data into temporary storage for the lifetime of the form using the unique identifier of the form
  • and clean up this temporary storage after use.
  • pre-initialize temporary storage and reuse it.

Otherwise, if an action is repeated many times in a form, for example, if a product is selected many times, this leads to unnecessary consumption of RAM, because temporary stores are accumulating.

Remember that when a value is retrieved from the temporary storage on the server, it will be retrieved by reference. This is a reference to the value that is stored in the cache. Within 20 minutes, from the moment it was put into the storage or from the moment of the last access, the value will be stored in the cache, and then written to disk and deleted from the cache. On the next call, the value is loaded from disk and put back into the cache.

Examples

1 - Example of correct code:

&НаКлиенте
Процедура ПриОбработкеПодобранныхТоваров(Элемент, АдресТоваровВХранилище, СтандартнаяОбработка) Экспорт
    Если АдресТоваровВХранилище = Неопределено Тогда
        Возврат;
    КонецЕсли;
    ПолучитьТоварыИзХранилища(АдресТоваровВХранилище);
КонецПроцедуры

&НаСервере
Процедура ПолучитьТоварыИзХранилища(АдресТоваровВХранилище)
    ПодобранныеТовары = ПолучитьИзВременногоХранилища(АдресТоваровВХранилище);
    Объект.Товары.Загрузить(ПодобранныеТовары);

    УдалитьИзВременногоХранилища(АдресТоваровДокумента); // очищается временное хранилище для минимизации расхода оперативной памяти
КонецПроцедуры

2 - Consider this recommendation when working with background jobs

Incorrect: - Each time a background job is executed, its result is placed in temporary storage for the lifetime of the form:

Parameters = LongOperations.FunctionParameters(UUID);
LongOperations.ExecFunction(Pframeters, BackgroundJobParameter);

  • If a long operation is performed by the user multiple times, then temporary storage accumulates, which causes an increase in memory consumption.
  • To reduce the consumption of RAM, in most cases, it is recommended to clear the temporary storage immediately after receiving the result of the background job:

Correct:

Настройки = ПолучитьИзВременногоХранилища(Результат.АдресРезультата);
УдалитьИзВременногоХранилища(Результат.АдресРезультата);  // Данные во временном хранилище больше не требуются.

  • If the result of a background job needs to be saved over several server calls, then it is necessary to transfer a fixed address of a previously initialized temporary storage:
    &AtServer
    Процедура ПриСозданииНаСервере(Отказ)
        АдресРезультатаФоновогоЗадания = ПоместитьВоВременноеХранилище(Неопределено, УникальныйИдентификатор); // Резервируем адрес временного хранилища
    EndProcedure
    
    &НаСервере
    Функция НачатьПоискНастроекУчетнойЗаписи()
        ПараметрыВыполнения = ДлительныеОперации.ПараметрыВыполненияФункции(УникальныйИдентификатор);
        ПараметрыВыполнения.АдресРезультата = АдресРезультатаФоновогоЗадания; // всегда используем одно и то же временное хранилище
    
        Возврат ДлительныеОперации.ВыполнитьФункцию(ПараметрыВыполнения,
            "Справочники.УчетныеЗаписиЭлектроннойПочты.ОпределитьНастройкиУчетнойЗаписи",
            АдресЭлектроннойПочты, Пароль);
    EndFunction
    

3 - Another example of preliminary initialization of temporary storage for reuse

// в форме документа
&НаСервере
Процедура ПриСозданииНаСервере(Отказ)
    АдресТоваров = ПоместитьВоВременноеХранилище(Неопределено, УникальныйИдентификатор); // Инициализируется реквизит формы
КонецПроцедуры

&НаСервере
Функция ТоварыВоВременномХранилище()
    Возврат ПоместитьВоВременноеХранилище(Товары.Выгрузить(), АдресТоваров);
КонецФункции

// и далее при переиспользовании временного хранилища не требуется удалять значение из временного хранилища:

&НаСервере
Процедура ПолучитьТоварыИзХранилища(АдресТоваровВХранилище)
    ПодобранныеТовары = ПолучитьИзВременногоХранилища(АдресТоваровВХранилище);
    Объект.Товары.Загрузить(ПодобранныеТовары);
КонецПроцедуры

Sources