Ejemplo n.º 1
0
    def handle(self, *apps, **options):
        """
        Handle the command
        """
        if not 1 <= len(apps) <= 2:
            print "Syntax : sesqllongquery <query> [<order>]"
            sys.exit(1)

        query = eval(apps[0])
        order = len(apps) == 2 and eval(apps[1]) or None

        print longquery(query, order).objs
Ejemplo n.º 2
0
    def handle(self, *apps, **options):
        """
        Handle the command
        """
        if not 1 <= len(apps) <= 2:
            print "Syntax : sesqllongquery <query> [<order>]"
            sys.exit(1)

        query = eval(apps[0])
        order = len(apps) == 2 and eval(apps[1]) or None
        
        print longquery(query, order).objs
Ejemplo n.º 3
0
 def handle_long(self):
     """
     Handle a long query
     """
     query = random.choice(self.queries)
     res = longquery(query[1], limit = self.options["long-limit"],
                     order = self.options["long-order"])
     return query[0] + " : %d results" % len(res)
Ejemplo n.º 4
0
    def sesql_amdin_query_add_filter(self, filter_expr, *args, **kwargs):
        from sesql import longquery
        name, value = filter_expr
        if not name.startswith("sesql:"):
            return original(self, filter_expr, *args, **kwargs)

        # Ok, a SeSQL filter ? Hum hum
        name = name.split(':', 1)[1]
        if "__" in name:
            name = name.split('__', 1)[0]
        name += "__containswords"
        query = longquery.longquery(
            Q(classname=self.model) & Q(**{name: value}))
        ids = [oid for klass, oid in query.objs]
        return original(self, ('id__in', ids), *args, **kwargs)
Ejemplo n.º 5
0
    def sesql_amdin_query_add_filter(self, filter_expr, *args, **kwargs):
        from sesql import longquery
        name, value = filter_expr
        if not name.startswith("sesql:"):
            return original(self, filter_expr, *args, **kwargs)

        # Ok, a SeSQL filter ? Hum hum
        name = name.split(':', 1)[1]
        if "__" in name:
            name = name.split('__', 1)[0]
        name += "__containswords"
        query = longquery.longquery(Q(classname = self.model) &
                                    Q(**{ name: value }))
        ids = [ oid for klass, oid in query.objs ]
        return original(self, ('id__in', ids), *args, **kwargs)
Ejemplo n.º 6
0
    def update(self, classnames, fields):
        """
        Reindex a single class
        """
        print "=> Starting reindexing columns %s." % ','.join(fields)
        result = longquery(Q(classname__in=classnames))
        nb = len(result)
        print "=> We got %d objects." % nb
        sys.stdout.flush()

        full_tmr = Timer()
        load_tmr = Timer()
        index_tmr = Timer()
        broken = 0

        def disp_stats():
            with index_tmr:
                transaction.commit()

            if not nb:
                return

            full_tmr.stop()
            elapsed = full_tmr.get_global()
            elapsed_last = full_tmr.peek()
            done = float(i + 1) / float(nb)
            eta = elapsed / done * (1 - done)
            print "**SeSQL update step stats**"
            print " - %d objects in %.2f s, rate %.2f" % (STEP, elapsed_last,
                                                          STEP / elapsed_last)
            lt = load_tmr.peek()
            it = index_tmr.peek()
            tt = (lt + it) / 100.0
            print " - loading: %.2f s (%04.1f %%), indexing: %.2f s (%04.1f %%)" % (
                lt, lt / tt, it, it / tt)
            print "**SeSQL global update stats**"
            print " - %d / %d ( %04.1f %% ) in %.2f s, rate %.2f, ETA %.2f s" % (
                i + 1, nb, 100 * done, elapsed, i / elapsed, eta)
            lt = load_tmr.get_global()
            it = index_tmr.get_global()
            tt = (lt + it) / 100.0
            print " - loading: %.2f s (%04.1f %%), indexing: %.2f s (%04.1f %%)" % (
                lt, lt / tt, it, it / tt)
            sys.stdout.flush()
            full_tmr.start()

        for i, obj in enumerate(result.objs):
            with load_tmr:
                try:
                    obj = result.load(obj)
                except ObjectDoesNotExist:
                    obj = None
                    broken += 1
                    log.warning("Object %r does not exist ! Broken index ?" %
                                (obj, ))
                except:
                    transaction.rollback()
                    raise
            with index_tmr:
                try:
                    update(obj, fields)
                except:
                    transaction.rollback()
                    raise

            if i % STEP == STEP - 1:
                disp_stats()

            del obj

        disp_stats()
Ejemplo n.º 7
0
    def update(self, classnames, fields):
        """
        Reindex a single class
        """
        print "=> Starting reindexing columns %s." % ",".join(fields)
        result = longquery(Q(classname__in=classnames))
        nb = len(result)
        print "=> We got %d objects." % nb
        sys.stdout.flush()

        full_tmr = Timer()
        load_tmr = Timer()
        index_tmr = Timer()
        broken = 0

        def disp_stats():
            with index_tmr:
                transaction.commit()

            if not nb:
                return

            full_tmr.stop()
            elapsed = full_tmr.get_global()
            elapsed_last = full_tmr.peek()
            done = float(i + 1) / float(nb)
            eta = elapsed / done * (1 - done)
            print "**SeSQL update step stats**"
            print " - %d objects in %.2f s, rate %.2f" % (STEP, elapsed_last, STEP / elapsed_last)
            lt = load_tmr.peek()
            it = index_tmr.peek()
            tt = (lt + it) / 100.0
            print " - loading: %.2f s (%04.1f %%), indexing: %.2f s (%04.1f %%)" % (lt, lt / tt, it, it / tt)
            print "**SeSQL global update stats**"
            print " - %d / %d ( %04.1f %% ) in %.2f s, rate %.2f, ETA %.2f s" % (
                i + 1,
                nb,
                100 * done,
                elapsed,
                i / elapsed,
                eta,
            )
            lt = load_tmr.get_global()
            it = index_tmr.get_global()
            tt = (lt + it) / 100.0
            print " - loading: %.2f s (%04.1f %%), indexing: %.2f s (%04.1f %%)" % (lt, lt / tt, it, it / tt)
            sys.stdout.flush()
            full_tmr.start()

        for i, obj in enumerate(result.objs):
            with load_tmr:
                try:
                    obj = result.load(obj)
                except ObjectDoesNotExist:
                    obj = None
                    broken += 1
                    log.warning("Object %r does not exist ! Broken index ?" % (obj,))
                except:
                    transaction.rollback()
                    raise
            with index_tmr:
                try:
                    update(obj, fields)
                except:
                    transaction.rollback()
                    raise

            if i % STEP == STEP - 1:
                disp_stats()

            del obj

        disp_stats()