-
-
Notifications
You must be signed in to change notification settings - Fork 618
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
Conversation
14f0d1b
to
44a400e
Compare
44a400e
to
992b809
Compare
_name = "mail.message.purge" | ||
_description = "Mail Message Purge" | ||
|
||
res_model = fields.Many2one( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
res_model = fields.Many2one( | |
model_id = fields.Many2one( |
or res_model_id
?
if self.include_user_notification: | ||
domain = AND( | ||
[ | ||
domain, | ||
[("message_type", "in", ("notification", "user_notification"))], | ||
] | ||
) | ||
else: | ||
domain = AND([domain, [("message_type", "=", "notification")]]) |
There was a problem hiding this comment.
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.
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() |
There was a problem hiding this comment.
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:
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, updated
There was a problem hiding this 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
<field name='name'>Purge Mail Messages</field> | ||
<field name='interval_number'>1</field> | ||
<field name='interval_type'>days</field> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
<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() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# __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. " |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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)]}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The indentations seem off
Thanks for the contribution, but isn't this module really similar to OCA/server-tools/autovacuum_message_attachment ? |
Thank you @Christian-RB, you are right, we didn't spotted this module! |
Will be using OCA/server-tools/autovacuum_message_attachment @Christian-RB thanks for pointing us in that direction |
No description provided.