Jump to content

a workflow that runs slowly with Alfred 3.1 but fast with 2


pyed

Recommended Posts

I just upgraded to Alfred 3, and I noticed that one of my old workflows works very slowly, it used to work just fine with Alfred 2

 

this workflow is just a bash script that takes a `{query}` and do a grep on a large log and display the output, I wrote it ~3 years ago and it is poorly written, I probably can re-write it and make it fast, but I'm hoping that it'll help you guys catch a bug with Alfred 3.

# 
#

name={query}

# will cat my log then i'll grep the $name;
# case insensitive with '-i' then i'll pass it to awk and print the title;
# then i'll pass to 'tr' to delete spaces "strip", then pass it again to 'tr';
# to replace new lines with spaces and save all that in var called result
result=`cat ~/log | grep -i $name | awk -F'|' '{print $7}' | tr -d ' ' | tr '\n' ' '`

# this variable will hold a long xml string that will be returned;
# I started with the end of it, because I'll reverse it in the end of the script;
# the reason I'm reversing it, to get the latest titles first;

xml='
</items>
'
# this loop go through every title in result and attach the proper xml tags to the var xml
for line in $result; do
xml=$xml"
  </item>
    <icon>icon.png</icon>
    <subtitle>$line</subtitle>
    <title>$line</title>
  <item uid=\"\" arg=\"none\" valid=\"no\" autocomplete=\"\">
"
done

# this is the head of xml 
xml=$xml'
<items>
<?xml version="1.0"?>
'
# this line here will flip the whole xml string.
xml=`echo "$xml" | sed '1!G;h;$!d'`


# print it in alfred window.
cat << EOB
$xml
EOB

the `~/log` file contains lines like:

|28-08-2016| |16:34 | |276766658   |  BillyBoy
|28-08-2016| |17:13 | |69352274    |  Goat
|29-08-2016| |13:52 | |868973148   |  Foobar
|30-08-2016| |04:49 | |72410542    |  HeyThere
|30-08-2016| |04:55 | |169608384   |  TheFirst
Link to comment
Share on other sites

sure I tested the script outside Alfred and it perfumed well.

 

If you've got the time, you can test it yourself

 

- save http://sprunge.us/fKCc to `~/log`

- install my workflow: https://cloudup.com/cwu5Q2bcrFw

 

then try to look for some names e.g. "have bart"

then try to look for a name that doesn't exist and see how much time it takes e.g. "have reta"

 

if you wanna test that script outside alfred, save http://sprunge.us/dKLH, run it e.g. $ bash script bart

Edited by pyed
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...