Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions endpoint_cache_preheat/README.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
=======================
Endpoint cache pre-heat
=======================

..
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:18f1a3985866b5d6564ce0c27a8c10a1cfd4e95a74fbc02eeee5789e2be63503
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
:target: https://odoo-community.org/page/development-status
:alt: Alpha
.. |badge2| image:: https://img.shields.io/badge/licence-LGPL--3-blue.png
:target: http://www.gnu.org/licenses/lgpl-3.0-standalone.html
:alt: License: LGPL-3
.. |badge3| image:: https://img.shields.io/badge/github-OCA%2Fweb--api-lightgray.png?logo=github
:target: https://github.com/OCA/web-api/tree/18.0/endpoint_cache_preheat
:alt: OCA/web-api
.. |badge4| image:: https://img.shields.io/badge/weblate-Translate%20me-F47D42.png
:target: https://translation.odoo-community.org/projects/web-api-18-0/web-api-18-0-endpoint_cache_preheat
:alt: Translate me on Weblate
.. |badge5| image:: https://img.shields.io/badge/runboat-Try%20me-875A7B.png
:target: https://runboat.odoo-community.org/builds?repo=OCA/web-api&target_branch=18.0
:alt: Try me on Runboat

|badge1| |badge2| |badge3| |badge4| |badge5|

Delay cache pre-heat for expensive endpoints.

If an endpoint takes to long to get cached, it will probably make your
call fail or any cron job that calls it.

This module allows pre-heat the cache and delay its generation.

.. IMPORTANT::
This is an alpha version, the data model and design can change at any time without warning.
Only for development or testing purpose, do not use in production.
`More details on development status <https://odoo-community.org/page/development-status>`_

**Table of contents**

.. contents::
:local:

Configuration
=============

Go to an endpoint form and tick Automatic cache pre-heat option.

Bug Tracker
===========

Bugs are tracked on `GitHub Issues <https://github.com/OCA/web-api/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us to smash it by providing a detailed and welcomed
`feedback <https://github.com/OCA/web-api/issues/new?body=module:%20endpoint_cache_preheat%0Aversion:%2018.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.

Do not contact contributors directly about support or help with technical issues.

Credits
=======

Authors
-------

* Camptocamp

Contributors
------------

- Simone Orsi <simone.orsi@camptocamp.com>

Maintainers
-----------

This module is maintained by the OCA.

.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org

OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.

.. |maintainer-simahawk| image:: https://github.com/simahawk.png?size=40px
:target: https://github.com/simahawk
:alt: simahawk

Current `maintainer <https://odoo-community.org/page/maintainer-role>`__:

|maintainer-simahawk|

This module is part of the `OCA/web-api <https://github.com/OCA/web-api/tree/18.0/endpoint_cache_preheat>`_ project on GitHub.

You are welcome to contribute. To learn how please visit https://odoo-community.org/page/Contribute.
1 change: 1 addition & 0 deletions endpoint_cache_preheat/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
20 changes: 20 additions & 0 deletions endpoint_cache_preheat/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Copyright 2025 Camptocamp SA
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

{
"name": "Endpoint cache pre-heat",
"summary": """Provide basic pre-caching features for endpoints""",
"version": "18.0.1.0.0",
"license": "LGPL-3",
"development_status": "Alpha",
"author": "Camptocamp, Odoo Community Association (OCA)",
"maintainers": ["simahawk"],
"website": "https://github.com/OCA/web-api",
"depends": ["endpoint_cache", "queue_job"],
"data": [
"views/endpoint_view.xml",
"data/cron.xml",
"data/job_channel.xml",
"data/job_function.xml",
],
}
17 changes: 17 additions & 0 deletions endpoint_cache_preheat/data/cron.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8" ?>
<odoo noupdate="1">
<record id="cron_endpoint_cache_preheat" model="ir.cron" forcecreate="True">
<field name="name">Endpoint cache pre-heat</field>
<field name="active" eval="True" />
<field name="user_id" ref="base.user_root" />
<field name="interval_number">1</field>
<field name="interval_type">days</field>
<field
name="nextcall"
eval="(datetime.now() + timedelta(days=1)).strftime('%Y-%m-%d 00:00:00')"
/>
<field name="model_id" ref="endpoint.model_endpoint_endpoint" />
<field name="state">code</field>
<field name="code">model.cron_endpoint_cache_preheat()</field>
</record>
</odoo>
6 changes: 6 additions & 0 deletions endpoint_cache_preheat/data/job_channel.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<odoo noupdate="1">
<record id="channel_endpoint_cache_root" model="queue.job.channel">
<field name="name">endpoint_cache</field>
<field name="parent_id" ref="queue_job.channel_root" />
</record>
</odoo>
7 changes: 7 additions & 0 deletions endpoint_cache_preheat/data/job_function.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<odoo noupdate="1">
<record id="job_fun_cron_endpoint_cache_preheat" model="queue.job.function">
<field name="model_id" ref="endpoint.model_endpoint_endpoint" />
<field name="method">_cron_endpoint_cache_preheat</field>
<field name="channel_id" ref="channel_endpoint_cache_root" />
</record>
</odoo>
73 changes: 73 additions & 0 deletions endpoint_cache_preheat/i18n/endpoint_cache_preheat.pot
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * endpoint_cache_preheat
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"Last-Translator: \n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: \n"

#. module: endpoint_cache_preheat
#: model_terms:ir.ui.view,arch_db:endpoint_cache_preheat.endpoint_mixin_form_view
msgid ""
"A job will be created to pre-heat the cache. You can check the status of the"
" job in the Jobs menu."
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat
msgid "Automatic cache pre-heat"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__display_name
msgid "Display Name"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.actions.server,name:endpoint_cache_preheat.cron_endpoint_cache_preheat_ir_actions_server
#: model:ir.cron,cron_name:endpoint_cache_preheat.cron_endpoint_cache_preheat
#: model:ir.cron,name:endpoint_cache_preheat.cron_endpoint_cache_preheat
msgid "Endpoint cache pre-heat"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model,name:endpoint_cache_preheat.model_endpoint_mixin
msgid "Endpoint mixin"
msgstr ""

#. module: endpoint_cache_preheat
#: model_terms:ir.ui.view,arch_db:endpoint_cache_preheat.endpoint_mixin_form_view
msgid "Force cache pre-heat (async)"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__id
msgid "ID"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,help:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat
#: model:ir.model.fields,help:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat
msgid ""
"If checked, cache will be pre-heated by a cron according to the selected "
"policy. Cache generation will be done in a queue job."
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin____last_update
msgid "Last Modified on"
msgstr ""

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat_ts
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat_ts
msgid "Last pre-heat on"
msgstr ""
81 changes: 81 additions & 0 deletions endpoint_cache_preheat/i18n/it.po
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# Translation of Odoo Server.
# This file contains the translation of the following modules:
# * endpoint_cache_preheat
#
msgid ""
msgstr ""
"Project-Id-Version: Odoo Server 14.0\n"
"Report-Msgid-Bugs-To: \n"
"PO-Revision-Date: 2025-06-09 14:26+0000\n"
"Last-Translator: mymage <stefano.consolaro@mymage.it>\n"
"Language-Team: none\n"
"Language: it\n"
"MIME-Version: 1.0\n"
"Content-Type: text/plain; charset=UTF-8\n"
"Content-Transfer-Encoding: \n"
"Plural-Forms: nplurals=2; plural=n != 1;\n"
"X-Generator: Weblate 5.10.4\n"

#. module: endpoint_cache_preheat
#: model_terms:ir.ui.view,arch_db:endpoint_cache_preheat.endpoint_mixin_form_view
msgid ""
"A job will be created to pre-heat the cache. You can check the status of the"
" job in the Jobs menu."
msgstr ""
"Verrà creato un lavoro per preriscaldare la cache. Puoi controllare lo stato "
"del lavoro nel menu Lavoro."

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat
msgid "Automatic cache pre-heat"
msgstr "Preriscaldamento cache automatico"

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__display_name
msgid "Display Name"
msgstr "Nome visualizzato"

#. module: endpoint_cache_preheat
#: model:ir.actions.server,name:endpoint_cache_preheat.cron_endpoint_cache_preheat_ir_actions_server
#: model:ir.cron,cron_name:endpoint_cache_preheat.cron_endpoint_cache_preheat
#: model:ir.cron,name:endpoint_cache_preheat.cron_endpoint_cache_preheat
msgid "Endpoint cache pre-heat"
msgstr "Preriscaldamento cache endpoint"

#. module: endpoint_cache_preheat
#: model:ir.model,name:endpoint_cache_preheat.model_endpoint_mixin
msgid "Endpoint mixin"
msgstr "Mixin endpoint"

#. module: endpoint_cache_preheat
#: model_terms:ir.ui.view,arch_db:endpoint_cache_preheat.endpoint_mixin_form_view
msgid "Force cache pre-heat (async)"
msgstr "Forza preriscaldamento cache (asincrono)"

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__id
msgid "ID"
msgstr "ID"

#. module: endpoint_cache_preheat
#: model:ir.model.fields,help:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat
#: model:ir.model.fields,help:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat
msgid ""
"If checked, cache will be pre-heated by a cron according to the selected "
"policy. Cache generation will be done in a queue job."
msgstr ""
"Se selezionata, la cache verrà preriscaldata da un cron in conformità alla "
"apolitica selezionata. La generazione della cache verrà eseguita in un "
"lavoro in coda."

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin____last_update
msgid "Last Modified on"
msgstr "Ultima modifica il"

#. module: endpoint_cache_preheat
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_endpoint__cache_preheat_ts
#: model:ir.model.fields,field_description:endpoint_cache_preheat.field_endpoint_mixin__cache_preheat_ts
msgid "Last pre-heat on"
msgstr "Ultimo preriscaldamento su"
1 change: 1 addition & 0 deletions endpoint_cache_preheat/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import endpoint_mixin
68 changes: 68 additions & 0 deletions endpoint_cache_preheat/models/endpoint_mixin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2025 Camptocamp SA
# @author: Simone Orsi <simone.orsi@camptocamp.com>
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl).

import logging

from odoo import api, fields, models

_logger = logging.getLogger(__name__)


class EndpointMixin(models.AbstractModel):
_inherit = "endpoint.mixin"

cache_preheat = fields.Boolean(
string="Automatic cache pre-heat",
help="If checked, cache will be pre-heated by a cron "
"according to the selected policy. "
"Cache generation will be done in a queue job.",
)
cache_preheat_ts = fields.Datetime(readonly=True, string="Last pre-heat on")

@api.model
def cron_endpoint_cache_preheat(self):
"""Cron job to preheat cache"""
now = fields.Datetime.now()
_logger.info("cron_endpoint_cache_preheat started")
base_domain = [("cache_policy", "!=", False), ("cache_preheat", "=", True)]
delta = {
"day": fields.Datetime.subtract(now, days=1),
"week": fields.Datetime.subtract(now, weeks=1),
"month": fields.Datetime.subtract(now, months=1),
}
for policy in ("day", "week", "month"):
domain = base_domain + [
("cache_policy", "=", policy),
"|",
(
"cache_preheat_ts",
"<=",
delta[policy].replace(hour=23, minute=59, second=59),
),
("cache_preheat_ts", "=", False),
]
for rec in self.search(domain):
rec.with_delay(
description=f"Pre-heat cache for endpoint {rec.route}"
)._cron_endpoint_cache_preheat()
_logger.info("cron_endpoint_cache_preheat preheated rec=%s", rec.id)
_logger.info("cron_endpoint_cache_preheat finished")
return True

def _cron_endpoint_cache_preheat(self):
"""Preheat cache for cron"""
self._endpoint_cache_preheat()
self.cache_preheat_ts = fields.Datetime.now()

def _endpoint_cache_wipe(self, domain):
# pylint: disable=missing-return
super()._endpoint_cache_wipe(domain)
self.cache_preheat_ts = False

def action_preheat_cache_async(self):
self.action_purge_cache_attachments()
self.with_delay(
description=f"Pre-heat cache for endpoint {self.route}"
)._cron_endpoint_cache_preheat()
return {"type": "ir.actions.act_window_close"}
3 changes: 3 additions & 0 deletions endpoint_cache_preheat/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
1 change: 1 addition & 0 deletions endpoint_cache_preheat/readme/CONFIGURE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Go to an endpoint form and tick Automatic cache pre-heat option.
1 change: 1 addition & 0 deletions endpoint_cache_preheat/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- Simone Orsi \<<simone.orsi@camptocamp.com>\>
6 changes: 6 additions & 0 deletions endpoint_cache_preheat/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Delay cache pre-heat for expensive endpoints.

If an endpoint takes to long to get cached, it will probably make your
call fail or any cron job that calls it.

This module allows pre-heat the cache and delay its generation.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading