MCPcopy Index your code
hub / github.com/1Panel-dev/MaxKB / batch

Method batch

apps/knowledge/serializers/problem.py:209–231  ·  view source on GitHub ↗
(self, problem_list, with_valid=True)

Source from the content-addressed store, hash-verified

207 raise AppApiException(500, _('Knowledge id does not exist'))
208
209 def batch(self, problem_list, with_valid=True):
210 if with_valid:
211 self.is_valid(raise_exception=True)
212 ProblemBatchSerializer(data={'problem_list': problem_list}).is_valid(raise_exception=True)
213 problem_list = list(set(problem_list))
214 knowledge_id = self.data.get('knowledge_id')
215 exists_problem_content_list = [
216 problem.content for problem in QuerySet(
217 Problem
218 ).filter(knowledge_id=knowledge_id, content__in=problem_list)
219 ]
220 problem_instance_list = [
221 Problem(
222 id=uuid.uuid7(), knowledge_id=knowledge_id, content=problem_content
223 ) for problem_content in problem_list if (
224 not exists_problem_content_list.__contains__(
225 problem_content
226 ) if len(exists_problem_content_list) > 0 else True
227 )
228 ]
229
230 QuerySet(Problem).bulk_create(problem_instance_list) if len(problem_instance_list) > 0 else None
231 return [ProblemSerializer(problem_instance).data for problem_instance in problem_instance_list]
232
233 class Query(serializers.Serializer):
234 workspace_id = serializers.CharField(required=True, label=_('workspace id'))

Callers 2

postMethod · 0.45
postMethod · 0.45

Calls 6

is_validMethod · 0.95
ProblemClass · 0.90
ProblemSerializerClass · 0.85
is_validMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected