<commit_before># Copyright 2018 <NAME>/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.fields import first
from odoo.tools.safe_eval import safe_eval
from odoo.osv import expression


class IntInstance(models.Model):
    _inherit = 'int.instance'

    member_count = fields.Integer(
        compute='_compute_member_count', string='Members')
    partner_ids = fields.Many2many(
        comodel_name="res.partner",
        string="Partners",
        relation="res_partner_int_instance",
        column2="partner_id",
        column1="int_instance_id",
    )
    partner_m2m_ids = fields.Many2many(
        comodel_name="res.partner",
        string="Users",
        relation="res_partner_int_instance_manager",
        column2="partner_id",
        column1="int_instance_id",
    )

    @api.multi
    @api.depends("partner_ids")
    def _compute_member_count(self):
        for inst in self:
            inst.member_count = len(inst.partner_ids.filtered(
                lambda p: not p.is_company))

    @api.multi
    def get_member_action(self):
        self.ensure_one()
        action = self.env.ref(
            "mozaik_person.res_partner_natural_person_action").read()[0]
        domain = [('int_instance_ids', 'in', [self.id])]
        if action.get('domain'):
            domain = expression.AND([domain, safe_eval(action.get('domain'))])
        action.update({
            'domain': domain,
        })<commit_msg>[FIX] performance issue: the filtered() testing a field of another model loads all data of all records of this model, and take a long for many records<commit_after># Copyright 2018 <NAME>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).

from odoo import api, fields, models
from odoo.fields import first
from odoo.tools.safe_eval import safe_eval
from odoo.osv import expression


class IntInstance(models.Model):
    _inherit = 'int.instance'

    member_count = fields.Integer(
        compute='_compute_member_count', string='Members')
    partner_m2m_ids = fields.Many2many(
        comodel_name="res.partner",
        string="Users",
        relation="res_partner_int_instance_manager",
        column2="partner_id",
        column1="int_instance_id",
    )

    @api.multi
    @api.depends("name")  # pseudo-depend
    def _compute_member_count(self):
        partner_obj = self.env['res.partner']
        for inst in self:
            inst.member_count = len(
                partner_obj.search(
                    [('int_instance_ids', 'in', [inst.id]),
                     ('is_company', '=', False)]))

    @api.multi
    def get_member_action(self):
        self.ensure_one()
        action = self.env.ref(
            "mozaik_person.res_partner_natural_person_action").read()[0]
        domain = [('int_instance_ids', 'in', [self.id])]
        if action.get('domain'):
            domain = expression.AND([domain, safe_eval(action.get('domain'))])
        action.update({
            'domain': domain,
        })
{'fraction_non_alphanumeric': 0.12232113419057039, 'fraction_numerical': 0.008242664029014177, 'mean_word_length': 2.768944099378882, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4327780', 'n_tokens_mistral': 956, 'n_tokens_neox': 937, 'n_words': 188}