MCPcopy
hub / github.com/1Panel-dev/MaxKB / save

Method save

apps/knowledge/models/knowledge.py:385–404  ·  view source on GitHub ↗
(self, bytea=None, force_insert=False, force_update=False, using=None, update_fields=None)

Source from the content-addressed store, hash-verified

383 db_table = "file"
384
385 def save(self, bytea=None, force_insert=False, force_update=False, using=None, update_fields=None):
386 if bytea is None:
387 raise ValueError("bytea参数不能为空")
388
389 sha256_hash = get_sha256_hash(bytea)
390 self.sha256_hash = sha256_hash
391 existing_file = QuerySet(File).filter(sha256_hash=sha256_hash).first()
392 if existing_file:
393 self.loid = existing_file.loid
394 self.file_size = existing_file.file_size
395 return super().save()
396
397 compressed_data = self._compress_data(bytea)
398 self.file_size = len(compressed_data)
399
400 self.loid = self._create_large_object()
401
402 self._write_compressed_data(compressed_data)
403 # 调用父类保存
404 return super().save()
405
406 def _compress_data(self, data, compression_level=9):
407 """压缩数据到内存"""

Callers 15

insertMethod · 0.95
to_toolMethod · 0.95
import_Method · 0.95
editMethod · 0.95
addMethod · 0.95
update_toolMethod · 0.95
uploadMethod · 0.95
uploadMethod · 0.95
_restore_source_fileMethod · 0.95
import_knowledgeMethod · 0.95
to_toolMethod · 0.95
parse_qa_fileMethod · 0.95

Calls 4

_compress_dataMethod · 0.95
_create_large_objectMethod · 0.95
get_sha256_hashFunction · 0.90

Tested by

no test coverage detected