##// END OF EJS Templates
api: allow uncached content fetching....
marcink -
r3479:58288c09 default
parent child Browse files
Show More
@@ -504,7 +504,8 b' def get_repo_nodes(request, apiuser, rep'
504 504
505 505 @jsonrpc_method()
506 506 def get_repo_file(request, apiuser, repoid, commit_id, file_path,
507 max_file_bytes=Optional(None), details=Optional('basic')):
507 max_file_bytes=Optional(None), details=Optional('basic'),
508 cache=Optional(True)):
508 509 """
509 510 Returns a single file from repository at given revision.
510 511
@@ -523,8 +524,10 b' def get_repo_file(request, apiuser, repo'
523 524 The valid options are ``minimal`` ``basic`` and ``full``.
524 525 :type details: Optional(str)
525 526 :param max_file_bytes: Only return file content under this file size bytes
526 :type details: Optional(int)
527
527 :type max_file_bytes: Optional(int)
528 :param cache: Use internal caches for fetching files. If disabled fetching
529 files is slower but more memory efficient
530 :type cache: Optional(bool)
528 531 Example output:
529 532
530 533 .. code-block:: bash
@@ -549,6 +552,7 b' def get_repo_file(request, apiuser, repo'
549 552 _perms = ('repository.admin', 'repository.write', 'repository.read',)
550 553 validate_repo_permissions(apiuser, repoid, repo, _perms)
551 554
555 cache = Optional.extract(cache, binary=True)
552 556 details = Optional.extract(details)
553 557 _extended_types = ['minimal', 'minimal+search', 'basic', 'full']
554 558 if details not in _extended_types:
@@ -574,7 +578,7 b' def get_repo_file(request, apiuser, repo'
574 578
575 579 node = ScmModel().get_node(
576 580 repo, commit_id, file_path, extended_info=extended_info,
577 content=content, max_file_bytes=max_file_bytes)
581 content=content, max_file_bytes=max_file_bytes, cache=cache)
578 582
579 583 except Exception:
580 584 log.exception("Exception occurred while trying to get repo node")
@@ -381,16 +381,25 b' class FileNode(Node):'
381 381 Returns md5, binary flag of the file node, without any cache usage.
382 382 """
383 383
384 if self.commit:
385 content = self.commit.get_file_content(self.path)
386 else:
387 content = self._content
384 content = self.content_uncached()
388 385
389 386 is_binary = content and '\0' in content
390 387 size = 0
391 388 if content:
392 389 size = len(content)
393 return is_binary, md5(content), size
390
391 return is_binary, md5(content), size, content
392
393 def content_uncached(self):
394 """
395 Returns lazily content of the FileNode. If possible, would try to
396 decode content from UTF-8.
397 """
398 if self.commit:
399 content = self.commit.get_file_content(self.path)
400 else:
401 content = self._content
402 return content
394 403
395 404 @LazyProperty
396 405 def content(self):
@@ -583,7 +583,7 b' class ScmModel(BaseModel):'
583 583 return _dirs, _files
584 584
585 585 def get_node(self, repo_name, commit_id, file_path,
586 extended_info=False, content=False, max_file_bytes=None):
586 extended_info=False, content=False, max_file_bytes=None, cache=True):
587 587 """
588 588 retrieve single node from commit
589 589 """
@@ -606,12 +606,21 b' class ScmModel(BaseModel):'
606 606
607 607 if extended_info:
608 608 file_data.update({
609 "md5": file_node.md5,
610 "binary": file_node.is_binary,
611 "size": file_node.size,
612 609 "extension": file_node.extension,
613 610 "mimetype": file_node.mimetype,
614 "lines": file_node.lines()[0]
611 })
612
613 if cache:
614 md5 = file_node.md5
615 is_binary = file_node.is_binary
616 size = file_node.size
617 else:
618 is_binary, md5, size, _content = file_node.metadata_uncached()
619
620 file_data.update({
621 "md5": md5,
622 "binary": is_binary,
623 "size": size,
615 624 })
616 625
617 626 if content:
@@ -619,7 +628,13 b' class ScmModel(BaseModel):'
619 628 and file_node.size > max_file_bytes)
620 629 full_content = None
621 630 if not file_node.is_binary and not over_size_limit:
622 full_content = safe_str(file_node.content)
631 if cache:
632 full_content = safe_str(file_node.content)
633 else:
634 if _content is None:
635 is_binary, md5, size, _content = \
636 file_node.metadata_uncached()
637 full_content = safe_str(_content)
623 638
624 639 file_data.update({
625 640 "content": full_content,
@@ -647,7 +662,7 b' class ScmModel(BaseModel):'
647 662 for f in files:
648 663 _content = None
649 664 _data = f_name = f.unicode_path
650 is_binary, md5, size = f.metadata_uncached()
665 is_binary, md5, size, _content = f.metadata_uncached()
651 666 _data = {
652 667 "name": h.escape(f_name),
653 668 "md5": md5,
General Comments 0
You need to be logged in to leave comments. Login now