diff --git a/grap_index/README.rst b/grap_index/README.rst new file mode 100644 index 00000000..e69de29b diff --git a/grap_index/__init__.py b/grap_index/__init__.py new file mode 100644 index 00000000..cb50dc9d --- /dev/null +++ b/grap_index/__init__.py @@ -0,0 +1,2 @@ +from . import models +from .hooks import drop_indexes diff --git a/grap_index/__manifest__.py b/grap_index/__manifest__.py new file mode 100644 index 00000000..10746561 --- /dev/null +++ b/grap_index/__manifest__.py @@ -0,0 +1,21 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +{ + "name": "GRAP - Custom Index", + "summary": "Add Extra postgresql Indexes", + "version": "12.0.1.0.1", + "category": "GRAP - Custom", + "author": "GRAP", + "website": "https://github.com/grap/grap-odoo-custom", + "license": "AGPL-3", + "depends": [ + # Odoo + "point_of_sale", + "purchase_stock", + "sale_stock", + ], + "installable": True, + "uninstall_hook": "drop_indexes", +} diff --git a/grap_index/hooks.py b/grap_index/hooks.py new file mode 100644 index 00000000..4d364e5b --- /dev/null +++ b/grap_index/hooks.py @@ -0,0 +1,25 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import logging + +from psycopg2.extensions import AsIs + +logger = logging.getLogger(__name__) + + +def drop_indexes(cr, registry): + indexes = { + "account_bank_statement_line": ["pos_statement_id"], + "pos_order": ["returned_order_id", "company_id"], + "pos_order_line": ["order_id"], + "stock_move": ["created_purchase_line_id", "inventory_id"], + "stock_move_line": ["picking_id"], + "stock_picking": ["group_id", "sale_id"], + } + + for table_name, field_names in indexes.items(): + for field_name in field_names: + index_name = "%s_%s_index" % (table_name, field_name) + logger.info("dropping posgresql index %s" % index_name) + cr.execute("DROP INDEX IF EXISTS %s;", (AsIs(index_name),)) diff --git a/grap_index/i18n/fr.po b/grap_index/i18n/fr.po new file mode 100644 index 00000000..e69de29b diff --git a/grap_index/models/__init__.py b/grap_index/models/__init__.py new file mode 100644 index 00000000..9db354bb --- /dev/null +++ b/grap_index/models/__init__.py @@ -0,0 +1,6 @@ +from . import account_bank_statement_line +from . import stock_move +from . import stock_move_line +from . import stock_picking +from . import pos_order +from . import pos_order_line diff --git a/grap_index/models/account_bank_statement_line.py b/grap_index/models/account_bank_statement_line.py new file mode 100644 index 00000000..ea274712 --- /dev/null +++ b/grap_index/models/account_bank_statement_line.py @@ -0,0 +1,11 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class AccountBankStatementLine(models.Model): + _inherit = "account.bank.statement.line" + + pos_statement_id = fields.Many2one(index=True) diff --git a/grap_index/models/pos_order.py b/grap_index/models/pos_order.py new file mode 100644 index 00000000..14530ce8 --- /dev/null +++ b/grap_index/models/pos_order.py @@ -0,0 +1,13 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class PosOrder(models.Model): + _inherit = "pos.order" + + returned_order_id = fields.Many2one(index=True) + + company_id = fields.Many2one(index=True) diff --git a/grap_index/models/pos_order_line.py b/grap_index/models/pos_order_line.py new file mode 100644 index 00000000..458120f3 --- /dev/null +++ b/grap_index/models/pos_order_line.py @@ -0,0 +1,11 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class PosOrderLine(models.Model): + _inherit = "pos.order.line" + + order_id = fields.Many2one(index=True) diff --git a/grap_index/models/stock_move.py b/grap_index/models/stock_move.py new file mode 100644 index 00000000..533175dc --- /dev/null +++ b/grap_index/models/stock_move.py @@ -0,0 +1,13 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockMove(models.Model): + _inherit = "stock.move" + + created_purchase_line_id = fields.Many2one(index=True) + + inventory_id = fields.Many2one(index=True) diff --git a/grap_index/models/stock_move_line.py b/grap_index/models/stock_move_line.py new file mode 100644 index 00000000..3fc792e4 --- /dev/null +++ b/grap_index/models/stock_move_line.py @@ -0,0 +1,11 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockMoveLine(models.Model): + _inherit = "stock.move.line" + + picking_id = fields.Many2one(index=True) diff --git a/grap_index/models/stock_picking.py b/grap_index/models/stock_picking.py new file mode 100644 index 00000000..db70f0c2 --- /dev/null +++ b/grap_index/models/stock_picking.py @@ -0,0 +1,13 @@ +# Copyright (C) 2023 - Today: GRAP (http://www.grap.coop) +# @author: Sylvain LE GAL (https://twitter.com/legalsylvain) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). + +from odoo import fields, models + + +class StockPicking(models.Model): + _inherit = "stock.picking" + + group_id = fields.Many2one(index=True) + + sale_id = fields.Many2one(index=True) diff --git a/grap_index/readme/CONTRIBUTORS.rst b/grap_index/readme/CONTRIBUTORS.rst new file mode 100644 index 00000000..e1525ce0 --- /dev/null +++ b/grap_index/readme/CONTRIBUTORS.rst @@ -0,0 +1 @@ +* Sylvain LE GAL (https://www.twitter.com/legalsylvain) diff --git a/grap_index/readme/DESCRIPTION.rst b/grap_index/readme/DESCRIPTION.rst new file mode 100644 index 00000000..24e074b2 --- /dev/null +++ b/grap_index/readme/DESCRIPTION.rst @@ -0,0 +1,21 @@ +This module add extra postgresql indexes to speed up SELECT queries. + +**"Purchase" performance** + +- ``stock_move``, on ``created_purchase_line_id`` + +**"Sale" performance** + +- ``stock_picking``, on ``sale_id`` + +**"Stock" performance** + +- ``stock_move``, on ``inventory_id`` +- ``stock_move_line``, on ``picking_id`` +- ``stock_picking``, on ``group_id`` + +**"Point of Sale" performance** + +- ``account_bank_statement_line``, on ``pos_statement_id`` +- ``pos_order``, on ``returned_order_id`` and ``company_id`` +- ``pos_order_line``, on ``order_id`` diff --git a/setup/grap_index/odoo/addons/grap_index b/setup/grap_index/odoo/addons/grap_index new file mode 120000 index 00000000..0cb07c78 --- /dev/null +++ b/setup/grap_index/odoo/addons/grap_index @@ -0,0 +1 @@ +../../../../grap_index \ No newline at end of file diff --git a/setup/grap_index/setup.py b/setup/grap_index/setup.py new file mode 100644 index 00000000..28c57bb6 --- /dev/null +++ b/setup/grap_index/setup.py @@ -0,0 +1,6 @@ +import setuptools + +setuptools.setup( + setup_requires=['setuptools-odoo'], + odoo_addon=True, +)