Closed mvaneijgen closed 2 years ago
That is not good!
When you were using 0.5, did you see any errors in the search results?
Sounds like code not exiting a loop, perhaps due to this addition to the code
while True:
if (parent_table == "block"):
try:
stack.append(recordMap.get('block').get(id).get('value').get('properties').get('title')[0][0])
except:
pass
parent_table = recordMap.get('block').get(id).get('value').get('parent_table')
id = recordMap.get('block').get(id).get('value').get('parent_id')
if (parent_table == "collection"):
try:
stack.append(recordMap.get('collection').get(id).get('value').get('name')[0][0])
except:
pass
parent_table = recordMap.get('collection').get(id).get('value').get('parent_table')
id = recordMap.get('collection').get(id).get('value').get('parent_id')
if (parent_table == "space"):
break
If the 100% CPU usage is reproducible, that would be very helpful to determine a fix.
No I can't see any errors in the debug console. I've made a screen recording. It doesn't create multiple Python instances, just each time I search a new one will be created, but they all use around the 90% CPU.
An easy fix will be to change the while true
loop to instead only loop 10 or 20 times, the logic builds the subtitle of the search result and aims to break out of the loop once it's traversed up the navigation tree. 10 should do, there are not many pages with more than 10 parent pages I'd say, and even if that was the case you wouldn't be able to fit more pages into the subtitle anyway.
To fix:
On line 207 change while True:
to
for x in range(10):
to notion.py in: ../Alfred Prefs/Alfred.alfredpreferences/workflows/user.workflow.0FA07E26-FD9B-49AD-B43E-B92E6C0D289E/
You might have a different user.worfklow folder, I'm not sure if that is the same for everyone.
Would you mind changing that line in your code, keeping the indentation the same? The change should be effective immediately, and some new notion searches will hopefully not cause 100% CPU. IF I've found the problem.
Just seen your video, I think that points towards the while true loop issue which is attempting to build the search subtitles. Will be interesting to see what your subtitles look like after the fix above, I presume one or two results might be missing subtitles (bearing in mind pages at the top level, ie space level, do not have subtitles anyway)
That fix seems to do the trick!
This is what my search result looks like.
Ah good news! Thank you for testing and for raising this issue, I'll push a fix. The next time you load a search and hit enter it should update automatically. For those currently experiencing this issue, hit enter in the ns workflow if you can, but you may need to update manually to the appropriate Alred4 or Alfred5 download as linked to here https://github.com/wrjlewis/notion-search-alfred-workflow
Thanks for your support @mvaneijgen 🙌 I've pushed a fix now so you can download that manually (Alfred5), if it hasn't already automatically updated.
You thanks for the support and the amazing work! 🎉
I had updated to the new version 0.5 and when searching I get three Python processes started on my machine with each use 90% of my CPU, also Alfred jumps to around 100% CPU and my laptop will sound like an apache helicopter 🚁. No search results will pop up. I've just downgraded to 0.4.3 and evrything works fine over there.
Alfred 5.0.5
macOS Monterey Version 12.6 (21G115) MacBook Pro (15-inch, 2017) Processor 3,1 GHz Quad-Core Intel Core i7 Memory 16 GB 2133 MHz LPDDR3 Graphics Intel HD Graphics 630 1536 MB