Optimize UserMessage.flags_list().

This small function was consuming way too much time when we
sent messages to many recipients.
This commit is contained in:
Steve Howell 2017-09-09 10:47:38 -07:00
parent b2f7c80ed2
commit 019d541e47

View File

@ -1320,7 +1320,17 @@ class AbstractUserMessage(ModelReprMixin, models.Model):
def flags_list(self):
# type: () -> List[str]
return [flag for flag in self.flags.keys() if getattr(self.flags, flag).is_set]
'''
This function is highly optimized, because it actually slows down
sending messages in a naive implementation.
'''
flags = int(self.flags)
names = self.ALL_FLAGS
return [
names[i]
for i in range(len(names))
if flags & (2 ** i)
]
def __unicode__(self):
# type: () -> Text