mirror of
https://github.com/KnugiHK/WhatsApp-Chat-Exporter.git
synced 2026-05-21 16:28:45 +00:00
Attempt to fix the perf issue in selectattr | first filter (#209)
Replace O(n²) Jinja2 filter searches with an O(1) dictionary lookup.
This commit is contained in:
@@ -213,6 +213,9 @@ def rendering(
|
|||||||
if "??" not in headline:
|
if "??" not in headline:
|
||||||
raise ValueError("Headline must contain '??' to replace with name")
|
raise ValueError("Headline must contain '??' to replace with name")
|
||||||
headline = headline.replace("??", name)
|
headline = headline.replace("??", name)
|
||||||
|
# Create a temporary lookup map only at render-time;
|
||||||
|
# media preview in reply is a UI-specific concern and
|
||||||
|
# is ignored by the core database processing
|
||||||
with open(output_file_name, "w", encoding="utf-8") as f:
|
with open(output_file_name, "w", encoding="utf-8") as f:
|
||||||
f.write(
|
f.write(
|
||||||
template.render(
|
template.render(
|
||||||
@@ -226,7 +229,8 @@ def rendering(
|
|||||||
previous=previous,
|
previous=previous,
|
||||||
status=chat.status,
|
status=chat.status,
|
||||||
media_base=chat.media_base,
|
media_base=chat.media_base,
|
||||||
headline=headline
|
headline=headline,
|
||||||
|
msg_map={m.key_id: m for m in msgs}.get
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -355,7 +355,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% set replied_msg = msgs | selectattr('key_id', 'equalto', msg.reply) | first %}
|
{% set replied_msg = msg_map(msg.reply) %}
|
||||||
{% if replied_msg and replied_msg.media == true %}
|
{% if replied_msg and replied_msg.media == true %}
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
{% if "image/" in replied_msg.mime %}
|
{% if "image/" in replied_msg.mime %}
|
||||||
@@ -461,7 +461,7 @@
|
|||||||
{% endif %}
|
{% endif %}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
{% set replied_msg = msgs | selectattr('key_id', 'equalto', msg.reply) | first %}
|
{% set replied_msg = msg_map(msg.reply) %}
|
||||||
{% if replied_msg and replied_msg.media == true %}
|
{% if replied_msg and replied_msg.media == true %}
|
||||||
<div class="flex-shrink-0">
|
<div class="flex-shrink-0">
|
||||||
{% if "image/" in replied_msg.mime %}
|
{% if "image/" in replied_msg.mime %}
|
||||||
|
|||||||
Reference in New Issue
Block a user