mirror of
https://github.com/zulip/zulip.git
synced 2026-07-15 21:03:26 +08:00
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:
parent
b2f7c80ed2
commit
019d541e47
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user