def load_all_posts_visits_from_csv(bucket, csv_file_record): visits_db_name = get_visits_db_name_for_bucket(bucket) current_visits_size = hsize(visits_db_name) if current_visits_size > 5000: # 如果超过了 5k 的数量,先clear,避免过度冗余 hclear(visits_db_name) raw_objects = csv_file_record.get('objects') or [] if not raw_objects: return if not isinstance(raw_objects, (list, tuple)): return for data_obj in raw_objects[:3000]: # 最多处理 3k 条记录,避免一个 bucket 过于庞大,出现性能问题 if not isinstance(data_obj, dict): continue path = data_obj.get('path') if not path or not isinstance(path, string_types): continue path = path.strip('/').lower() if not is_a_markdown_file(path): continue visits = to_int(data_obj.get('visits'), default_if_fail=0) visitors = to_int(data_obj.get('visitors'), default_if_fail=0) visits_key = get_visits_key(path, field='visits') visitors_key = get_visits_key(path, field='visitors') hset(visits_db_name, visits_key, visits) hset(visits_db_name, visitors_key, visitors)
def get_bucket_full_info(bucket): info = {} configs = get_bucket_init_configs(bucket) user_configs = get_bucket_user_configs(bucket) info['configs'] = configs info['user_configs'] = user_configs info['size'] = hsize(bucket) meta_info = get_bucket_meta_info(bucket) info.update(meta_info) return info
def get_records_count(bucket): return hsize(bucket)
def get_bucket_size(bucket): # count records of bucket size = hsize(bucket) or 0 return size
def get_bound_wechat_accounts_count(bucket): namespace = get_bucket_namespace_for_wechat(bucket) return hsize(namespace)