Edit: Post corrected.
I just made an alias. A lot of people create pacman hooks and what not but an alias is just must simplier. I use Fish shell so the actual creation of the alias is a bit different but here are the commands it runs, automatic first refreshing the mirror list, rank mirror list, update, update AUR then trim. First the alias that refreshes the mirror and then the alias that combine that with the trimming (basically having an Alias call and Alias):
sudo reflector --verbose --protocol https --latest 20 --sort rate --save /etc/pacman.d/mirrorlist
This is the code for my alias “mirrors” that creates a mirror list of the 20 latest updated mirrors in the world at the moment ranked on speed.
mirrors && sudo pacman -Syyu && yay -Syyua && sudo paccache -rk 2
This is the alias “update”; first it runs the alias mirrors above, combine it with a pacman and yay complete system upgrade (I know yay can do it all, but…) and then the last command trims the paccache.
The -rk flag determins how many backup copies are saved. Default, if you don’t use the flag, it saves 3. That seems exsessive to me so I run it with the -rk 2 to only keep one backup.