def forwards(self, orm): from drawquest.apps.drawquest_auth.models import User from canvas.redis_models import redis completed_user_ids = [int(e) for e in redis.smembers('following_migration_completed_user_ids')] for user in User.objects.all(): if user.id in completed_user_ids: continue print user.username, followers = user.redis.followers.smembers() followers = User.objects.filter(id__in=followers).order_by('username').values_list('id', flat=True) for id_ in reversed(followers): user.redis.new_followers.bump(id_) following = user.redis.followers.smembers() following = User.objects.filter(id__in=following).order_by('username').values_list('id', flat=True) for id_ in reversed(following): user.redis.new_following.bump(id_) redis.sadd('following_migration_completed_user_ids', user.id) redis.delete('following_migration_completed_user_ids') print
def handle(self, *args, **options): if not settings.COMPRESS_OFFLINE and not options.get('force'): print "COMPRESS_OFFLINE must be True, or --force used to run." return # Make output dir. subprocess.check_call(['mkdir', '-p', COMPILED_OUTPUT_DIR]) compiled_paths, compiled_s3_paths, compiled_s3_urls = {}, {}, {} for bundle_name, input_files in SCRIPTS.items(): # Compile JS. output_path = os.path.join(COMPILED_OUTPUT_DIR, bundle_name) args = closure_args(input_files, output_path) print subprocess.check_output(args, stderr=subprocess.STDOUT) # Rename files with hash suffixes. suffix = '-' + subprocess.check_output(['git', 'hash-object', output_path]).strip() hashed_output_name = '{}{}.js'.format(bundle_name, suffix) hashed_output_path = os.path.join(COMPILED_OUTPUT_DIR, hashed_output_name) os.rename(output_path, hashed_output_path) compiled_paths[bundle_name] = hashed_output_path compiled_s3_path = compiled_s3_paths[bundle_name] = s3_path(hashed_output_name) compiled_s3_urls[bundle_name] = s3_url(compiled_s3_path) # Upload to S3. for bundle_name, local_path in compiled_paths.items(): upload_compiled_js_to_s3(local_path, compiled_s3_paths[bundle_name]) redis.delete('compiled_js_file_urls') redis.hmset('compiled_js_file_urls', compiled_s3_paths)
def combine_upload_chunks(request, chunks, metadata, is_quest=False): keys = ['chunk:{0}'.format(chunk) for chunk in chunks] raw_values = redis.mget(keys) if not all(raw_values): raise ServiceError("Missing uploaded chunk, please retry.") values = [b64decode(val) for val in raw_values] filedata = "".join(values) fs = get_fs(*settings.IMAGE_FS) remix_of = metadata.get('remix_of') stamps_used = metadata.get('used_stamps', []) or [] text_used = metadata.get('used_text', '') or '' redis.delete(*keys) try: return create_content(request.META['REMOTE_ADDR'], fs, filedata, remix_of, stamps_used, text_used, '', is_quest=is_quest) except IOError, e: raise ServiceError("Unable to read image.")
def preload_explore_comment_ids(): redis.delete('explore_comment_ids_temp') ids = explore_comment_ids() for id_ in ids: redis.sadd('explore_comment_ids_temp', id_) if ids: redis.rename('explore_comment_ids_temp', 'explore_comment_ids')
def comment_freeze(request): ctx = {} if request.method == 'POST': ts = request.POST['comment_freeze_ts'] if ts: redis.set('dq:comment_freeze_ts', ts) else: redis.delete('dq:comment_freeze_ts') signals.comment_freeze_ts_changed.send(None) ctx['comment_freeze_ts'] = redis.get('dq:comment_freeze_ts') or '' return r2r_jinja('comment_freeze/comment_freeze.html', ctx, request)
def forwards(self, orm): from drawquest.apps.drawquest_auth.models import User from drawquest.apps.drawquest_auth.details_models import UserDetails from canvas.redis_models import redis completed_user_ids = [ int(e) for e in redis.smembers('following_migration_completed_user_ids') ] try: highest_completed = max(completed_user_ids) except ValueError: highest_completed = 0 all_users = User.objects.all() print 'Gathering all_usernames...' all_usernames = dict( (int(id_), username.lower()) for id_, username in all_users.values_list('id', 'username')) print 'Done' print 'Beginning all_users iteration...' for user in all_users.filter(id__gte=highest_completed): if user.id in completed_user_ids: print 'Skipping {}'.format(user.id) continue print user.username, '({})'.format(user.id) followers = user.redis.followers.smembers() ids = sorted(followers, key=lambda f: all_usernames.get(int(f), 'fff')) for f in reversed(ids): user.redis.new_followers.bump(f) user.redis.new_following.zremrangebyrank(0, -1) following = user.redis.following.smembers() ids = sorted(following, key=lambda f: all_usernames.get(int(f), 'fff')) for f in reversed(ids): user.redis.new_following.bump(f) redis.sadd('following_migration_completed_user_ids', user.id) redis.delete('following_migration_completed_user_ids') print
def forwards(self, orm): from canvas.redis_models import redis from drawquest.apps.drawquest_auth.models import User for user in User.objects.all(): if redis.delete(user.redis.dismissed_quests.key): print user.username elif user.id % 1000 == 0: print user.id,
def forwards(self, orm): from drawquest.apps.drawquest_auth.models import User from drawquest.apps.drawquest_auth.details_models import UserDetails from canvas.redis_models import redis completed_user_ids = [int(e) for e in redis.smembers('following_migration_completed_user_ids')] try: highest_completed = max(completed_user_ids) except ValueError: highest_completed = 0 all_users = User.objects.all() print 'Gathering all_usernames...' all_usernames = dict((int(id_), username.lower()) for id_, username in all_users.values_list('id', 'username')) print 'Done' print 'Beginning all_users iteration...' for user in all_users.filter(id__gte=highest_completed): if user.id in completed_user_ids: print 'Skipping {}'.format(user.id) continue print user.username, '({})'.format(user.id) followers = user.redis.followers.smembers() ids = sorted(followers, key=lambda f: all_usernames.get(int(f), 'fff')) for f in reversed(ids): user.redis.new_followers.bump(f) user.redis.new_following.zremrangebyrank(0, -1) following = user.redis.following.smembers() ids = sorted(following, key=lambda f: all_usernames.get(int(f), 'fff')) for f in reversed(ids): user.redis.new_following.bump(f) redis.sadd('following_migration_completed_user_ids', user.id) redis.delete('following_migration_completed_user_ids') print
def combine_upload_chunks(request, chunks, metadata, is_quest=False): keys = ['chunk:{0}'.format(chunk) for chunk in chunks] raw_values = redis.mget(keys) if not all(raw_values): raise ServiceError("Missing uploaded chunk, please retry.") values = [b64decode(val) for val in raw_values] filedata = "".join(values) fs = get_fs(*settings.IMAGE_FS) remix_of = metadata.get('remix_of') stamps_used = metadata.get('used_stamps', []) or [] text_used = metadata.get('used_text', '') or '' redis.delete(*keys) try: return create_content(request.META['REMOTE_ADDR'], fs, filedata, remix_of, stamps_used, is_quest=is_quest) except IOError, e: raise ServiceError("Unable to read image.")
def forwards(self, orm): from drawquest.apps.drawquest_auth.models import User from canvas.redis_models import redis completed_user_ids = [ int(e) for e in redis.smembers('following_migration_completed_user_ids') ] for user in User.objects.all(): if user.id in completed_user_ids: continue print user.username, followers = user.redis.followers.smembers() followers = User.objects.filter( id__in=followers).order_by('username').values_list('id', flat=True) for id_ in reversed(followers): user.redis.new_followers.bump(id_) following = user.redis.followers.smembers() following = User.objects.filter( id__in=following).order_by('username').values_list('id', flat=True) for id_ in reversed(following): user.redis.new_following.bump(id_) redis.sadd('following_migration_completed_user_ids', user.id) redis.delete('following_migration_completed_user_ids') print
def disable_auto_curate(): redis.delete('dq:auto_curate')
def after_setUp(self): redis.delete('redis_object_key') self.hash = self.create_hash()
def after_setUp(self): redis.delete('rh_key') self.rh = RedisHash('rh_key')
def after_setUp(self): self.prefix = "test_notification:" for key in redis.keys(self.prefix + "*"): redis.delete(key) self.q = KeyedSet(self.prefix)
def after_setUp(self): redis.delete('rblf_key') self.lbf = RedisLastBumpedBuffer('rblf_key', 3)
def forwards(self, orm): "Write your forwards methods here." for key in redis.keys("user_pins*"): redis.delete(key)
def disable(): redis.delete('dq:comment_freeze_id') invalidate_namespace('comments')