How TransientModel data cleaned and How odoo Maintain Auto Clean

 TransientModel




class TransientModel(Model):

Transient Model created by Model Super-class. All users can create new records, and may only access the records they created. The superuser has unrestricted access to all TransientModel records of all user created.


_transient_max_count= 0

maximum number of transient records, unlimited if 0

_transient_max_hours= 1.0

maximum idle lifetime (in hours), unlimited if 0

Actual cleaning will happen only once every 5 minutes. This means this method can be called frequently (e.g. whenever a new record is created).

_transient_vacuum()


with both max_hours and max_count active This method unlinks old records from the transient model tables whenever the _transient_max_count or _transient_max_hours conditions (if any) are reached.


Suppose max_hours = 0.2 (aka 12 minutes), max_count = 20, there are 55 rows in the table, 10 created/changed in the last 5 minutes, an additional 12 created/changed between 5 and 10 minutes ago, the rest created/changed more than 12 minutes ago.

- age based vacuum will leave the 22 rows created/changed in the last 12 minutes

- count based vacuum will wipe out another 12 rows. Not just 2, otherwise each addition would immediately cause the maximum to be reached again.

- the 10 rows that have been created/changed the last 5 minutes will NOT be deleted


How odoo Maintain Auto Clean ?


Odoo made a schedular to clean  TransientModel's data from database. The scheduled action to clean up the database, including the TransientModel​’s data is named "Base: Auto-vacuum internal data" and it can be found at 

Settings > Technical > Automation > Scheduled Actions​

The default interval for running is once per day. Perform a complete database cleanup by safely calling every ``@api.autovacuum`` decorated method.

From a security perspective, all users can create new records of a TransientModel​, however, they can access only the records that they have created, except for the superuser, which can access all records. Also, when using this class should be taken into consideration that Many2one relations are not allowed with a non-transient model.

Comments