django.ddb.reset_queries

Here are the examples of the python api django.ddb.reset_queries taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

2 Examples 7

Example 1

Project: ssbc Source File: loadhash.py
Function: handle
    def handle(self, *args, **options):
        Hash.objects.all().delete()
        print 'inputing ...'
        total = db.basic.count()
        ii = 0
        ready = []
        for x in db.basic.find():
            ii += 1
            if ii % 10000 == 0:
                print ii * 100 / total, '%', total - ii
                Hash.objects.bulk_create(ready)
                ready = []
                ddb.reset_queries()

            h = Hash(info_hash = x['info_hash'])
            h.classified = x.get('classified', False)
            h.tagged = x.get('tagged', False)

            h.name = unicode(x.get('name',''))[:255]
            h.category = x.get('category','')[:20]
            h.extension = x.get('extension', '')[:20]
            h.data_hash = x.get('data_hash', '')
            h.comment = x.get('comment','')[:255]
            h.creator = x.get('creator','')[:20]

            h.length = x.get('length', 0)
            h.requests = x.get('requests', 0)
            h.source_ip = x.get('source_ip')
            h.create_time = x.get('create_time')
            h.last_seen = x.get('last_seen', h.create_time)
            ready.append(h)

        if ready:
            Hash.objects.bulk_create(ready)

Example 2

Project: ssbc Source File: loadlist.py
Function: handle
    def handle(self, *args, **options):
        #FileList.objects.all().delete()
        print 'inputing ...'
        total = db.filelist.count()
        ii = 0
        ready = []
        for x in db.filelist.find():
            ii += 1
            if ii % 200 == 0:
                try:
                    FileList.objects.bulk_create(ready)
                except:
                    for r in ready:
                        try:
                            r.save()
                        except:
                            import traceback
                            traceback.print_exc()
                ready = []
            if ii % 10000 == 0:
                print ii * 100 / total, '%', total - ii
                ddb.reset_queries()

            h = FileList()
            h.info_hash = binascii.hexlify(x['_id'])
            h.file_list = json.dumps(x['files'])
            ready.append(h)

        if ready:
            FileList.objects.bulk_create(ready)