Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][ADD] mail_message_purge #1503

Closed
wants to merge 2 commits into from

Conversation

TDu
Copy link
Member

@TDu TDu commented Nov 18, 2024

No description provided.

@TDu TDu force-pushed the 14-add-mail-message-purge branch from 14f0d1b to 44a400e Compare November 18, 2024 10:51
@TDu TDu force-pushed the 14-add-mail-message-purge branch from 44a400e to 992b809 Compare November 18, 2024 12:11
_name = "mail.message.purge"
_description = "Mail Message Purge"

res_model = fields.Many2one(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
res_model = fields.Many2one(
model_id = fields.Many2one(

or res_model_id?

Comment on lines 50 to 58
if self.include_user_notification:
domain = AND(
[
domain,
[("message_type", "in", ("notification", "user_notification"))],
]
)
else:
domain = AND([domain, [("message_type", "=", "notification")]])
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if we want to restrict the purge to these two message_type only, what about comment, email etc?
We could add another domain configurable to apply on mail.message, which defaults to [('message_type', 'in', ['email', 'comment', 'notification', 'user_notification'])]. This default could be automatically computed based on <mail.message>._fields['message_type'].selection value so it will include all other types like snailmail, depending on modules installed.

Comment on lines 73 to 83
def _purge(self):
domain = self._domain_mail_message_purge()
messages = self.env["mail.message"].search(domain, limit=1000)
_logger.info(f"Purging {len(messages)} messages for {self.res_model.model}")
messages.unlink()

@api.model
def _cron_purge_mail_message(self):
records = self.env["mail.message.purge"].search([])
for record in records:
record._purge()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This limit has to be configurable through the cron task as we could generate more than 1000 messages a day on a given data model:

Suggested change
def _purge(self):
domain = self._domain_mail_message_purge()
messages = self.env["mail.message"].search(domain, limit=1000)
_logger.info(f"Purging {len(messages)} messages for {self.res_model.model}")
messages.unlink()
@api.model
def _cron_purge_mail_message(self):
records = self.env["mail.message.purge"].search([])
for record in records:
record._purge()
def _purge(self, limit=1000):
domain = self._domain_mail_message_purge()
messages = self.env["mail.message"].search(domain, limit=limit)
_logger.info(f"Purging {len(messages)} messages for {self.res_model.model}")
messages.unlink()
@api.model
def _cron_purge_mail_message(self, limit=1000):
records = self.env["mail.message.purge"].search([])
for record in records:
record._purge(limit=limit)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, updated

Copy link

@henrybackman henrybackman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just some small things caught my eye

Comment on lines +7 to +9
<field name='name'>Purge Mail Messages</field>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<field name='name'>Purge Mail Messages</field>
<field name='interval_number'>1</field>
<field name='interval_type'>days</field>
<field name="name">Purge Mail Messages</field>
<field name="interval_number">1</field>
<field name="interval_type">days</field>

def _domain_mail_message_purge(self):
"""Generate a domain to search for mail message to purge."""
self.ensure_one()
# __import__("pdb").set_trace()

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# __import__("pdb").set_trace()

all_message_type = fields.Boolean(
string="All message types",
default=True,
help="If unchecked a domain will allow to customize the message to be purged. "

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
help="If unchecked a domain will allow to customize the message to be purged. "
help="If unchecked a domain will allow to customize the message types to be purged. "

name="mail_message_domain"
widget="domain"
options="{'in_dialog': True, 'model': 'mail.message'}"
attrs="{'invisible': [('all_message_type', '=', True)]}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The indentations seem off

@Christian-RB
Copy link

Thanks for the contribution, but isn't this module really similar to OCA/server-tools/autovacuum_message_attachment ?

@sebalix
Copy link
Contributor

sebalix commented Nov 20, 2024

Thank you @Christian-RB, you are right, we didn't spotted this module!

@TDu
Copy link
Member Author

TDu commented Nov 28, 2024

Will be using OCA/server-tools/autovacuum_message_attachment @Christian-RB thanks for pointing us in that direction

@TDu TDu closed this Nov 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants