aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTrygve Aaberge <trygveaa@gmail.com>2024-01-11 01:29:13 +0100
committerTrygve Aaberge <trygveaa@gmail.com>2024-02-18 12:56:37 +0100
commitbb80ee68763233930a6f4169b07a029cd99b589d (patch)
tree80bba0d394b2e0d40b3464998267d5469cfaaff5
parent24e21c91a03f32b43af9178e15df0574256c9ce7 (diff)
downloadwee-slack-bb80ee68763233930a6f4169b07a029cd99b589d.tar.gz
Improve performance of rerender_history for WeeChat >= 4.0.0
Previously each message was rerendered individually. This meant that for each message, we start at the bottom of the buffer and go through all the lines upwards until we find the message. So the lines were looped through a lot of times which was slow. Now we instead go through all the lines once, look up the message for each line and updates it. This is only for >= 4.0.0 since earlier versions may have multiple lines for each message (when the message has multiple lines). That would complicate this way of updating the messages, and I don't think it's worth implementing it when it's only for an old version.
-rw-r--r--slack/slack_buffer.py39
1 files changed, 32 insertions, 7 deletions
diff --git a/slack/slack_buffer.py b/slack/slack_buffer.py
index 3c78ba3..920b877 100644
--- a/slack/slack_buffer.py
+++ b/slack/slack_buffer.py
@@ -289,15 +289,40 @@ class SlackBuffer(ABC):
if self.buffer_pointer is None:
return
- modify_buffer_line(
- self.buffer_pointer,
- message.ts,
- await message.render_message(context=self.context, rerender=True),
- )
+ new_text = await message.render_message(context=self.context, rerender=True)
+ modify_buffer_line(self.buffer_pointer, message.ts, new_text)
async def rerender_history(self):
- for message in self.messages.values():
- await self.rerender_message(message)
+ if self.buffer_pointer is None:
+ return
+
+ if shared.weechat_version >= 0x04000000:
+ own_lines = weechat.hdata_pointer(
+ weechat.hdata_get("buffer"), self.buffer_pointer, "own_lines"
+ )
+ line_pointer = weechat.hdata_pointer(
+ weechat.hdata_get("lines"), own_lines, "last_line"
+ )
+
+ while line_pointer:
+ ts = hdata_line_ts(line_pointer)
+ if ts:
+ message = self.messages[ts]
+ new_text = await message.render_message(
+ context=self.context, rerender=True
+ )
+ data = weechat.hdata_pointer(
+ weechat.hdata_get("line"), line_pointer, "data"
+ )
+ weechat.hdata_update(
+ weechat.hdata_get("line_data"), data, {"message": new_text}
+ )
+ line_pointer = weechat.hdata_move(
+ weechat.hdata_get("line"), line_pointer, -1
+ )
+ else:
+ for message in self.messages.values():
+ await self.rerender_message(message)
def set_typing_self(self):
now = time.time()