Revision 5576e6dd snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py

b/snf-pithos-backend/pithos/backends/lib/sqlalchemy/node.py
32 32
# or implied, of GRNET S.A.
33 33

  
34 34
from time import time
35
from operator import itemgetter
36
from itertools import groupby
37

  
35 38
from sqlalchemy import Table, Integer, BigInteger, DECIMAL, Column, String, MetaData, ForeignKey
36 39
from sqlalchemy.types import Text
37 40
from sqlalchemy.schema import Index, Sequence
......
178 181
    columns.append(Column('key', String(128), primary_key=True))
179 182
    columns.append(Column('value', String(256)))
180 183
    attributes = Table('attributes', metadata, *columns, mysql_engine='InnoDB')
184
    Index('idx_attributes_domain', attributes.c.domain)
181 185

  
182 186
    metadata.create_all(engine)
183 187
    return metadata.sorted_tables
......
1104 1108
        l = r.fetchone()
1105 1109
        r.close()
1106 1110
        return l
1111

  
1112
    def domain_object_list(self, domain, cluster=None):
1113
        """Return a list of (path, property list, attribute dictionary)
1114
           for the objects in the specific domain and cluster.
1115
        """
1116

  
1117
        v = self.versions.alias('v')
1118
        n = self.nodes.alias('n')
1119
        a = self.attributes.alias('a')
1120

  
1121
        s = select([n.c.path, v.c.serial, v.c.node, v.c.hash, v.c.size,
1122
                    v.c.type, v.c.source, v.c.mtime, v.c.muser, v.c.uuid,
1123
                    v.c.checksum, v.c.cluster, a.c.key, a.c.value])
1124
        s = s.where(n.c.node == v.c.node)
1125
        s = s.where(n.c.latest_version == v.c.serial)
1126
        if cluster:
1127
            s = s.where(v.c.cluster == cluster)
1128
        s = s.where(v.c.serial == a.c.serial)
1129
        s = s.where(a.c.domain == domain)
1130

  
1131
        r = self.conn.execute(s)
1132
        rows = r.fetchall()
1133
        r.close()
1134

  
1135
        group_by = itemgetter(slice(12))
1136
        rows.sort(key = group_by)
1137
        groups = groupby(rows, group_by)
1138
        return [(k[0], k[1:], dict([i[12:] for i in data])) \
1139
            for (k, data) in groups]

Also available in: Unified diff