Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

加快docx导出速度、更详细的过程输出 #296

Merged
merged 4 commits into from
Jan 11, 2024
Merged

加快docx导出速度、更详细的过程输出 #296

merged 4 commits into from
Jan 11, 2024

Conversation

zetaloop
Copy link
Contributor

💻 变更类型 | Change Type

  • ✨ feat
  • 🐛 fix
  • ♻️ refactor
  • 💄 style
  • 🔨 chore
  • 📝 docs

🔀 变更说明 | Description of Change

  1. 在导出过程中,添加更多运行过程输出,以便用户了解运行状态。
  2. 对于 docx 导出,原本为每一条记录追加一次,改为每200条一组再合并。增加依赖库 docxcompose。
  3. 顺便修复 CSV 导出结束 okSignal 的值。

📝 补充信息 | Additional Information

  1. 之前我在使用软件时,因为一份对话过多,导出时间太长了,进度条一直在99%,无法确定是程序卡了还是在处理中。于是,我为一些耗时的处理添加了过程输出,这样用户就可以知道程序在运行,而不是报错卡了。

  2. 对于一次共22736条消息的导出,新的 docx 导出方法用173s完成整个导出,而原版在200s时仅完成了5625条,大概四分之一,并且越来越慢。
    (↓这是原版↓)
    image

  3. okSignal = pyqtSignal(int),因此 emit 1 而不是 'ok'。

okSignal = pyqtSignal(int),见 output.py
可用于判断程序是在缓慢处理中还是卡了,对于特别多的对话记录,ui进度条是几乎不动的
对话记录特别多的时候,越往后word文件越大,添加一个记录所需时间也越长。 先将每200条记录保存,最后合并在一起,将整个过程大大加快。
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jan 11, 2024
@LC044 LC044 merged commit 189f89a into LC044:master Jan 11, 2024
@zetaloop zetaloop deleted the faster-docx-clearer-progress branch January 11, 2024 13:56
@LC044
Copy link
Owner

LC044 commented Jan 11, 2024

image

兄弟你导出Word的时候内存如何

@zetaloop
Copy link
Contributor Author

导了一次(22736条消息),没这么大,不过好像是没释放内存
image

@LC044
Copy link
Owner

LC044 commented Jan 12, 2024

我批量导出三个人的达到了7G,而有些人总是喜欢全选

@zetaloop
Copy link
Contributor Author

确实,我刚全选试了一下,内存吃到8G多。
我看看能不能在导出的时候直接合并掉,不然一直产生新的小文档很耗内存

@LC044
Copy link
Owner

LC044 commented Jan 12, 2024

我之前的解决方案是分n份用多线程处理,保存n个docx文件,最后再合并到一起再把n个文件删了

@zetaloop
Copy link
Contributor Author

zetaloop commented Jan 12, 2024

试了一下,无论是在newdoc里一边导出一边合并,还是在newdoc里直接保存后面拼起来,在单线程的情况下都没能缓解内存问题。
怀疑 python-docx 这个模块的内存管理是不是有一点问题(

此外,还遇到了 All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters.
(看到修复了)

@LC044
Copy link
Owner

LC044 commented Jan 12, 2024

试试最新代码

@zetaloop
Copy link
Contributor Author

试试最新代码

最新代码成功解决该问题,不会再出现非法字符报错。
#297

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size:M This PR changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants