Last active
December 21, 2015 01:38
-
-
Save snopoke/6228998 to your computer and use it in GitHub Desktop.
Find usage count of CouchDB views
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Basic script to find all references to CouchDB views in code. | |
# 1. Find all 'map.js' files | |
# 2. Based on some assumptions about the structure they are in | |
# generate the CouchDB view name. | |
# 3. Look for all references of that name in all ".py" files. | |
# | |
# Output saved to 'view_usage.csv' | |
OUTPUT=view_usage.csv | |
maps=`find . -name map.js` | |
for m in $maps | |
do | |
IFS='/' read -a array <<< "$m" | |
len=${#array[@]} | |
if [ ${array[$len-4]} == "_design" ]; then | |
view="${array[$len-5]}/${array[$len-2]}" | |
else | |
view="${array[$len-4]}/${array[$len-2]}" | |
fi | |
matches=$(find . -iname '*.py' | xargs grep "$view" -sl | tr '\n' ' ') | |
IFS=' ' read -a matcharr <<< "$matches" | |
echo -n "." | |
echo "$view,${#matcharr[@]},$matches" >> $OUTPUT | |
sort -t\, -k2 -n $OUTPUT -o $OUTPUT | |
done | |
echo "Output saved to $OUTPUT" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment