diff --git a/includes/oa_core.util.inc b/includes/oa_core.util.inc
index 03f1094..1a0c25c 100644
--- a/includes/oa_core.util.inc
+++ b/includes/oa_core.util.inc
@@ -1144,8 +1144,9 @@ function oa_core_get_user_spaces($uid) {
 /**
  * Helper function to return the id of the space/group that contains the nid node
  *
- * This function is called a lot, so it needs to be fast
- * Do not use node_load here!
+ * This function is called a lot, so it needs to be fast.
+ * node_load() is only called when entitycache is available, otherwise the
+ * database is queried directly.
  *
  * @param $node
  *  A numeric NID or a complete $node object.
@@ -1153,14 +1154,20 @@ function oa_core_get_user_spaces($uid) {
  *  an array of content types that this node can be part of.
  *
  * @return
- *  An numberic NID that this content is part of.
+ *  A numeric NID that this content is part of. If $node is a group or not member
+ *  of a group, its NID is returned.
  */
 function oa_core_get_group_from_node($node, $allowed_types = array(OA_SPACE_TYPE, OA_GROUP_TYPE)) {
+  // Loading a node is cheap when entity cache is installed.
+  if (module_exists('entitycache') && !is_object($node)) {
+    $node = node_load($node);
+  }
+
   $cache = &drupal_static('oa_core_groups', array());
   // Find the NID in case a $node object was passed in..
   if (is_object($node) && !empty($node->nid)) {
     $nid = $node->nid;
-    if (!empty($node_type) && in_array($node->type, $allowed_types)) {
+    if (!empty($allowed_types) && in_array($node->type, $allowed_types)) {
       $cache[$nid] = $nid;
     }
   }
@@ -1172,24 +1179,43 @@ function oa_core_get_group_from_node($node, $allowed_types = array(OA_SPACE_TYPE
     return $cache[$nid];
   }
 
-  $query = db_select('og_membership', 'f');
-  $query->leftJoin('node', 'n', "n.nid = f.gid");
-  $result = $query
-    ->fields('f', array('gid'))
-    ->condition('f.etid', $nid)
-    ->condition('f.group_type', 'node')
-    ->condition('f.entity_type', 'node')
-    ->condition('f.field_name', OA_SPACE_FIELD)
-    ->condition('n.type', $allowed_types, 'IN')
-    ->execute()
-    ->fetchAssoc();
+  $cache[$nid] = $nid;
+
+  if (module_exists('entitycache') && is_object($node)) {
+    $groupitems = field_get_items('node', $node, OA_SPACE_FIELD);
+    if (!empty($groupitems)) {
+      foreach ($groupitems as $groupitem) {
+        if (empty($allowed_types)) {
+          $cache[$nid] = $groupitem['target_id'];
+          break;
+        }
 
-  if (!empty($result)) {
-    $cache[$nid] = $result['gid'];
+        $group = node_load($groupitem['target_id']);
+        if ($group && in_array($group->type, $allowed_types)) {
+          $cache[$nid] = $group->nid;
+          break;
+        }
+      }
+    }
   }
   else {
-    $cache[$nid] = $nid;
+    $query = db_select('og_membership', 'f');
+    $query->leftJoin('node', 'n', 'n.nid = f.gid');
+    $result = $query
+      ->fields('f', array('gid'))
+      ->condition('f.etid', $nid)
+      ->condition('f.group_type', 'node')
+      ->condition('f.entity_type', 'node')
+      ->condition('f.field_name', OA_SPACE_FIELD)
+      ->condition('n.type', $allowed_types, 'IN')
+      ->execute()
+      ->fetchAssoc();
+
+    if (!empty($result)) {
+      $cache[$nid] = $result['gid'];
+    }
   }
+
   return $cache[$nid];
 }
 
