From 2f2c18177e8a054b4970085bd6f75a4e2a482f1a Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 28 Oct 2013 13:34:20 +0100 Subject: [PATCH 1/3] SQL optimization --- toys/createindex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/toys/createindex b/toys/createindex index 1f356e5..39e3484 100755 --- a/toys/createindex +++ b/toys/createindex @@ -338,8 +338,8 @@ SELECT tags.track, tags.year, source_files.size -FROM source_files - INNER JOIN mime_types +FROM mime_types + INNER JOIN source_files ON source_files.mime_type=mime_types.id INNER JOIN tags ON source_files.id=tags.source_file From 666b9a0ab49a243e9bdef26034f6a6b0c69f4189 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 28 Oct 2013 13:35:23 +0100 Subject: [PATCH 2/3] createindex: Top 5 genres --- toys/createindex | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/toys/createindex b/toys/createindex index 39e3484..8f3464c 100755 --- a/toys/createindex +++ b/toys/createindex @@ -573,6 +573,52 @@ unset types counts counpcts sizes sizepcts echo ' +Top 5 genres:' +maxgenrelen=5 +maxcountlen=5 +unset counts genres +echo ' + SELECT genre, + COUNT(*) + FROM tags + WHERE genre NOT NULL + GROUP BY genre + ORDER BY COUNT(*) DESC + LIMIT 5; + +SELECT "AtOM:NoMoreFiles";' >&3 + +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] +do + genre="${line%%::AtOM:SQL:Sep::*}" + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + count="${rest%%::AtOM:SQL:Sep::*}" + counts+=( "$count" ) + genres+=( "$genre" ) + maxcountlen=$(( ${#count} > maxcountlen ? ${#count} : maxcountlen )) + maxgenrelen=$(( ${#genre} > maxgenrelen ? ${#genre} : maxgenrelen )) + read -u4 line +done +head=$( + printf "| # | %'${maxcountlen}s | %-${maxgenrelen}s |" \ + Count Genre +) +sep=${head//[^|]/-} +sep=${sep//\|/+} +echo "$sep" +echo "$head" +echo "$sep" +for id in ${!genres[@]} +do + printf "| %i | %'${maxcountlen}i | %-${maxgenrelen}s |\n" \ + $(( id + 1 )) \ + "${counts[id]}" \ + "${genres[id]}" + echo "$sep" +done +unset line genre count rest genres counts maxgenrelen maxcountlen + ' echo ' SELECT COUNT(*),SUM(size) From 3080d9de45809a69520d664d84a5f11d1a1dd8a1 Mon Sep 17 00:00:00 2001 From: Vincent Riquer Date: Mon, 28 Oct 2013 13:36:04 +0100 Subject: [PATCH 3/3] createindex: Top 10 artists --- toys/createindex | 52 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 51 insertions(+), 1 deletion(-) diff --git a/toys/createindex b/toys/createindex index 8f3464c..0b2ec41 100755 --- a/toys/createindex +++ b/toys/createindex @@ -619,7 +619,57 @@ do done unset line genre count rest genres counts maxgenrelen maxcountlen -' +echo ' + +Top 10 artists:' +maxartistlen=6 +maxcountlen=5 +unset counts artists +echo ' + SELECT artist, + COUNT(*) + FROM tags + WHERE artist NOT NULL + GROUP BY artist + ORDER BY COUNT(*) DESC + LIMIT 10; + +SELECT "AtOM:NoMoreFiles";' >&3 + +read -u4 line +until [[ $line == AtOM:NoMoreFiles ]] +do + artist="${line%%::AtOM:SQL:Sep::*}" + rest="${line#*::AtOM:SQL:Sep::}::AtOM:SQL:Sep::" + count="${rest%%::AtOM:SQL:Sep::*}" + counts+=( "$count" ) + artists+=( "$artist" ) + maxcountlen=$(( ${#count} > maxcountlen ? ${#count} : maxcountlen )) + maxartistlen=$(( ${#artist} > maxartistlen ? ${#artist} : maxartistlen )) + read -u4 line +done +head=$( + printf "| # | %'${maxcoutlen}s | %-${maxartistlen}s |" \ + Count Artist +) +sep=${head//[^|]/-} +sep=${sep//\|/+} +echo "$sep" +echo "$head" +echo "$sep" +for id in ${!artists[@]} +do + printf "| %2i | %'${maxcountlen}i | %-${maxartistlen}s |\n" \ + $(( id + 1 )) \ + "${counts[id]}" \ + "${artists[id]}" + echo "$sep" +done +unset line artist count rest artists counts maxartistlen maxcountlen + +echo ' + +File formats:' echo ' SELECT COUNT(*),SUM(size) FROM source_files