Skip to content

Instantly share code, notes, and snippets.

@greggles
Last active November 12, 2015 18:37
Show Gist options
  • Save greggles/df1faa38ab27798e8e38 to your computer and use it in GitHub Desktop.
Save greggles/df1faa38ab27798e8e38 to your computer and use it in GitHub Desktop.
Which database methods in Drupal are used most often?
# Grep for db_select and grab the next 5 lines
# grep and sed those lines to find db methods
# isolate the methods
# count them.
# I ran this in the core: modules/ directory, would be interesting to see results from a mix of sites/all/modules/ directories
➜ grep -hr -A 5 "db_select" . | grep "\->" | sed 's/^[ ]*//' | sed 's/\$[a-z]*//' | grep "^-" | awk -F\( '{print $1}' | sort | uniq -c | sort -rn
184 ->condition
168 ->fields
87 ->addField
70 ->execute
49 ->orderBy
47 ->join
31 ->addTag
22 ->countQuery
22 ->addExpression
14 ->range
12 ->extend
10 ->fetchField
10 ->assertEqual
8 ->leftJoin
6 ->where
6 ->groupBy
5 ->distinct
5 ->addMetaData
4 ->orderRandom
4 ->innerJoin
4 ->element
3 ->searchExpression
3 ->limit
2 ->setCountQuery
2 ->notExists
2 ->isNull
2 ->isNotNull
2 ->having
2 ->exists
2 ->assertNotIdentical
1 ->weight = $query->execute
1 ->searchexpression
1 ->fetchAllAssoc
1 ->choice = db_select
➜ grep -hr -A 5 "db_delete" . | grep "\->" | sed 's/^[ ]*//' | sed 's/\$[a-z]*//' | grep "^-" | awk -F\( '{print $1}' | sort | uniq -c | sort -rn
245 ->condition
176 ->execute
7 ->fields
5 ->assertEqual
4 ->assertIdentical
3 ->where
2 ->rollback
2 ->notExists
2 ->drupalLogin
1 ->values
1 ->drupalLogout
1 ->drupalGet
1 ->assertTrue
1 ->assertFalse
➜ grep -hr -A 5 "db_update" . | grep "\->" | sed 's/^[ ]*//' | sed 's/\$[a-z]*//' | grep "^-" | awk -F\( '{print $1}' | sort | uniq -c | sort -rn
228 ->condition
199 ->fields
173 ->execute
28 ->assertIdentical
12 ->expression
4 ->where
3 ->isNotNull
3 ->assertTrue
1 ->drupalGet
1 ->assertRaw
➜ grep -hr -A 5 "db_insert" . | grep "\->" | sed 's/^[ ]*//' | sed 's/\$[a-z]*//' | grep "^-" | awk -F\( '{print $1}' | sort | uniq -c | sort -rn
134 ->fields
71 ->execute
67 ->values
10 ->from
5 ->useDefaults
4 ->assertTrue
4 ->assertIdentical
2 ->pass
2 ->fail
1 ->countQuery
1 ->condition
1 ->assertFalse
1 ->assertEqual
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment