MCPcopy
hub / github.com/isso-comments/isso / fetch

Method fetch

isso/views/comments.py:937–1034  ·  view source on GitHub ↗
(self, environ, request, uri)

Source from the content-addressed store, hash-verified

935
936 @requires(str, "uri")
937 def fetch(self, environ, request, uri):
938 args = {"uri": uri, "after": request.args.get("after", 0)}
939
940 # map sort query parameter
941 valid_sort_options = ["newest", "oldest", "upvotes"]
942 sort = request.args.get("sort", "oldest")
943
944 if sort not in valid_sort_options:
945 return BadRequest("Invalid sort option. Must be one of: 'newest', 'oldest', 'upvotes'")
946
947 if sort == "newest":
948 args["order_by"] = "created"
949 args["asc"] = 0
950 elif sort == "oldest":
951 args["order_by"] = "created"
952 args["asc"] = 1
953 elif sort == "upvotes":
954 args["order_by"] = "karma"
955 args["asc"] = 0
956
957 try:
958 args["limit"] = int(request.args.get("limit"))
959 except TypeError:
960 args["limit"] = None
961 except ValueError:
962 return BadRequest("limit should be integer")
963
964 try:
965 args["offset"] = int(request.args.get("offset", 0))
966 if args["offset"] < 0:
967 return BadRequest("offset should not be negative")
968 except (ValueError, TypeError):
969 return BadRequest("offset should be integer")
970
971 if request.args.get("parent") is not None:
972 try:
973 args["parent"] = int(request.args.get("parent"))
974 root_id = args["parent"]
975 except ValueError:
976 return BadRequest("parent should be integer")
977 else:
978 args["parent"] = None
979 root_id = None
980
981 plain = request.args.get("plain", "0") == "0"
982
983 reply_counts = self.comments.reply_count(uri)
984
985 if args["limit"] == 0:
986 root_list = []
987 else:
988 root_list = list(self.comments.fetch(**args))
989
990 if root_id not in reply_counts:
991 reply_counts[root_id] = 0
992
993 # We need to calculate the total number of comments for the root response value
994 total_replies = sum(reply_counts.values()) if root_id is None else reply_counts[root_id]

Callers 4

fetchCommentsFunction · 0.45
insert_loaderFunction · 0.45
feedMethod · 0.45
notify_usersMethod · 0.45

Calls 3

_process_fetched_listMethod · 0.95
reply_countMethod · 0.80
getMethod · 0.45

Tested by

no test coverage detected