Beispiel #1
0
    def update_record_when_file_stored(self,
                                       bucket,
                                       record_data,
                                       file_size=None,
                                       image_info=None):
        # 原则上,我们是不允许对 record 进行修改的,因为文件分开了存储,做一个妥协性的对应
        # 主要是 accept_upload_file_from_client 上调用后,要再调用本函数
        if not isinstance(record_data, dict):
            return
        record_id = record_data.get("_id")
        if not record_id:
            record_id = get_record_id_by_path(bucket,
                                              path=record_data.get("path"))
        if not is_object_id(record_id):
            return
        if record_data.get("_file_stored"):
            return

        # 走 update_record 的逻辑
        kwargs_to_update = {"_file_stored": True}
        if file_size is not None:
            kwargs_to_update["file_size"] = file_size
        if image_info and isinstance(image_info, dict):
            image_info.pop("_id", None)  # in case, try remove _id
            kwargs_to_update.update(image_info)
        update_record(bucket=bucket, record_id=record_id, **kwargs_to_update)
        file_size = kwargs_to_update.get("file_size")
        increase_file_size_for_bucket(bucket, file_size)
Beispiel #2
0
def record_id_to_date_string(record_id):
    if not record_id:
        return ''
    if not is_object_id(record_id):
        return ''
    record_id = ObjectID(record_id)
    date = record_id.generation_time
    date_string = date.strftime('%Y-%m-%d %H:%M:%S UTC')
    return date_string
Beispiel #3
0
def create_record_by_sync(bucket, record, check_bucket=False):
    if not isinstance(record, dict):
        return 'record is not a dict'
    record_id = record.pop('_id', None)
    if not record_id:
        return 'record_id is missing'
    if not is_object_id(record_id):
        return 'record_id is not a valid ObjectID'
    error_info = get_record_data_error_info(record)
    if error_info:
        return error_info
    if check_bucket: # current node has the bucket or not
        if not has_bucket(bucket):
            return 'no bucket matched'

    py_record_data = ssdb_data_to_py_data(record)

    saved = hset(bucket, record_id, py_record_data, ignore_if_exists=True)
    if saved:
        after_record_created(bucket, py_record_data, object_id=record_id, )
Beispiel #4
0
def set_bucket_last_record_id_computed(bucket, record_id):
    # 因为 files_info 是需要计算的,只有在需要的时候 (也就是 client 端获取 files 信息的时候),才进行一次计算
    if not is_object_id(record_id):
        return
    hset("buckets_file_cursor_computed", bucket, record_id)
Beispiel #5
0
def set_bucket_last_record_id(bucket, record_id):
    # # path 相关的,因为有 delete 的关系,单独进行 last_record_id 的存储,不然直接 hget_max 就可以了
    if not is_object_id(record_id):
        return
    hset("buckets_file_cursor", bucket, record_id)