Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#16896 closed Cleanup/optimization (needsinfo)

ComentDetailsForm.clean_comment calls lower() in each iteration

Reported by: gasull@… Owned by: nobody
Component: contrib.comments Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


I would change this line from

bad_words = [w for w in settings.PROFANITIES_LIST if w in comment.lower()]


lowercased_comment = comment.lower()
bad_words = [w for w in settings.PROFANITIES_LIST if w in lowercased_comment]


This way lower() won't need to be run on each iteration.

Change History (3)

comment:1 Changed 4 years ago by carljm

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

Ugh - this code is still in Django? I think it's about time to deprecate PROFANITIES_LIST and COMMENTS_ALLOW_PROFANITIES (the latter doesn't even seem to be documented, but its default value is False - i.e. block profanities.)

Anyway, as long as we've got the code it may as well not be stupidly inefficient. Thanks for the report!

comment:2 Changed 4 years ago by Alex

  • Resolution set to needsinfo
  • Status changed from new to closed

I'm closign as needsinfo, unless someone has a profile showing that this is a significant portion of a real request, there's no point to have addition code churn. Plus, as Carl notes, this code really should be deprecated.

comment:3 Changed 4 years ago by lukeplant

In 1.3 we said "No more naughty words" and waved off the Scunthorpe problem by setting PROFANITIES_LIST to an empty list by default, which is tantamount to deprecating the functionality. But technically we didn't deprecate the setting, and COMMENTS_ALLOW_PROFANITIES. We should do that for 1.4.

Note: See TracTickets for help on using tickets.
Back to Top