Exemple #1
0
    def do_update(self):
        version = self.r.get('version')
        if not version:
            self.r.set('version', 8)
            return

        version = int(version)
        r = JSONRedis(self.r.r)
        r.caching = False

        # Deprecated since 0.14.0
        if version < 7:
            now = time()
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                r.zadd('{}.lists'.format(lst['authors'][0]), {lst['id']: -now})
            r.set('version', 7)

        # Deprecated since 0.23.0
        if version < 8:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                users_key = '{}.users'.format(lst['id'])
                self.r.zadd(users_key, {lst['authors'][0].encode(): 0})
                events = r.omget(r.lrange('{}.activity.items'.format(lst['id']), 0, -1))
                for event in reversed(events):
                    t = parse_isotime(event['time'], aware=True).timestamp()
                    self.r.zadd(users_key, {event['user'].encode(): -t})
            r.set('version', 8)
Exemple #2
0
    def do_update(self):
        version = self.r.get('version')
        if not version:
            self.r.set('version', 7)
            return

        version = int(version)
        r = JSONRedis(self.r.r)
        r.caching = False

        # Deprecated since 0.3.0
        if version < 2:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['features'] = []
                items = r.omget(r.lrange('{}.items'.format(lst['id']), 0, -1))
                for item in items:
                    item['checked'] = False
                r.omset({item['id']: item for item in items})
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 2)

        # Deprecated since 0.5.0
        if version < 3:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['activity'] = (Activity('{}.activity'.format(lst['id']),
                                            app=self,
                                            subscriber_ids=[]).json())
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 3)

        # Deprecated since 0.6.0
        if version < 4:
            items = r.omget([
                id for list_id in r.lrange('lists', 0, -1)
                for id in r.lrange('{}.items'.format(list_id.decode()), 0, -1)
            ])
            for item in items:
                item['location'] = None
            r.omset({item['id']: item for item in items})
            r.set('version', 4)

        # Deprecated since 0.7.0
        if version < 5:
            items = r.omget([
                id for list_id in r.lrange('lists', 0, -1)
                for id in r.lrange('{}.items'.format(list_id.decode()), 0, -1)
            ])
            for item in items:
                item['resource'] = None
            r.omset({item['id']: item for item in items})
            r.set('version', 5)

        # Deprecated since 0.11.0
        if version < 6:
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                lst['mode'] = 'collaborate'
            r.omset({lst['id']: lst for lst in lists})
            r.set('version', 6)

        # Deprecated since 0.14.0
        if version < 7:
            now = time()
            lists = r.omget(r.lrange('lists', 0, -1))
            for lst in lists:
                r.zadd('{}.lists'.format(lst['authors'][0]), {lst['id']: -now})
            r.set('version', 7)