Guest User

Untitled

a guest
Feb 18th, 2018
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.82 KB | None | 0 0
  1. Total time: 0.012725 s
  2. File: /home/amanda-simbiose/Documents/API_s1search/slicing_dice-api_python3/api/tests/insertion_performance/wrk_scripts/insert_for_profile.py
  3. Function: process_entities_in_request_for_test at line 305
  4.  
  5. Line # Hits Time Per Hit % Time Line Contents
  6. ==============================================================
  7. 305 async def process_entities_in_request_for_test(entities, client_id, project_id,
  8. 306 dimension,
  9. 307 test, permission_fields,
  10. 308 permitted_fields,
  11. 309 auto_create, permission,
  12. 310 force_new_entity=False):
  13. 311
  14. 312 1 4.0 4.0 0.0 entity_ids, remaining_names = await util.get_entity_ids(
  15. 313 1 6.0 6.0 0.0 entities.keys(), str(client_id), str(project_id), test, dimension,
  16. 314 1 8633.0 8633.0 67.8 force_new_entity=force_new_entity)
  17. 315 1 3.0 3.0 0.0 if test:
  18. 316 metrics_name = "new-entities-test"
  19. 317 else:
  20. 318 1 2.0 2.0 0.0 metrics_name = "new-entities"
  21. 319
  22. 320 1 5.0 5.0 0.0 if project_id != METRICS.project_id and len(remaining_names) > 1:
  23. 321 data_to_metric = await make_metric_command(
  24. 322 metrics_name, client_id, project_id, len(remaining_names))
  25. 323 METRICS.add_to_bulk(data_to_metric)
  26. 324
  27. 325 1 3.0 3.0 0.0 fields_as_search, list_of_field_values = get_fields(project_id,
  28. 326 1 2.0 2.0 0.0 dimension,
  29. 327 1 2.0 2.0 0.0 entities,
  30. 328 1 2.0 2.0 0.0 (permission_fields,
  31. 329 1 2.0 2.0 0.0 permitted_fields,
  32. 330 1 2.0 2.0 0.0 permission),
  33. 331 1 642.0 642.0 5.0 test)
  34. 332
  35. 333 2 7.0 3.5 0.1 for field_ in fields_as_search:
  36. 334 1 2.0 2.0 0.0 if field_['api_name'] == "":
  37. 335 raise exceptions.FieldInvalidApiNameError(
  38. 336 endpoint="Index", apiname=field_['api_name'])
  39. 337
  40. 338 1 5.0 5.0 0.0 s1search_field_name = util.get_s1search_name(
  41. 339 1 14.0 14.0 0.1 project_id, dimension, 'entity-id', test)
  42. 340 1 23.0 23.0 0.2 if not util.check_field_cache(project_id, dimension, s1search_field_name):
  43. 341 dict_entity_id = {
  44. 342 1 3.0 3.0 0.0 "api_name": "entity-id",
  45. 343 1 3.0 3.0 0.0 "table": dimension
  46. 344 }
  47. 345 1 2.0 2.0 0.0 fields_as_search.append(dict_entity_id)
  48. 346 1 2.0 2.0 0.0 list_of_field_values.append(dict_entity_id)
  49. 347
  50. 348 1 3.0 3.0 0.0 util.add_field_cache(project_id, dimension, s1search_field_name,
  51. 349 1 30.0 30.0 0.2 dict_entity_id)
  52. 350 1 13.0 13.0 0.1 field_uniq = [_f for _f in fields_as_search if
  53. 351 _f['api_name'] == 'entity-id']
  54. 352 1 2.0 2.0 0.0 if not field_uniq:
  55. 353 entity_id = util.check_field_cache(project_id, dimension,
  56. 354 s1search_field_name)
  57. 355 fields_as_search.append(entity_id)
  58. 356 list_of_field_values.append(entity_id)
  59. 357 1 2.0 2.0 0.0 if fields_as_search:
  60. 358 1 3.0 3.0 0.0 fields_as = util.search_fields_as(project_id, dimension,
  61. 359 1 250.0 250.0 2.0 fields_as_search, test)
  62. 360 else:
  63. 361 fields_as = []
  64. 362 1 9.0 9.0 0.1 new_fields = set([x for x in fields_as if isinstance(x, str)])
  65. 363 1 5.0 5.0 0.0 new_fields = list(new_fields)
  66. 364 1 3.0 3.0 0.0 if len(new_fields) > 0:
  67. 365 if 'column' in auto_create:
  68. 366 fields_as = await index.auto_create_fields_s1(
  69. 367 client_id, project_id, dimension, test, new_fields,
  70. 368 list_of_field_values, permission, auto_create)
  71. 369 else:
  72. 370 if new_fields == ["entity-id"]:
  73. 371 fields_as = await index.auto_create_fields_s1(
  74. 372 client_id, project_id, dimension, test, new_fields,
  75. 373 list_of_field_values, permission, auto_create)
  76. 374 else:
  77. 375 raise exceptions.IndexFieldNotActiveError(
  78. 376 parameter=new_fields[0])
  79. 377
  80. 378 51 121.0 2.4 1.0 for entity_name, fields in entities.items():
  81. 379 50 126.0 2.5 1.0 if len(entity_name) > ENTITY_NAME_MAX_LENGTH:
  82. 380 LOGGER.info('Entity name is too big %s', entity_name)
  83. 381 raise exceptions.IndexEntityNameTooBigError(more_info={
  84. 382 'entity-id': entity_name,
  85. 383 'max-length': ENTITY_NAME_MAX_LENGTH
  86. 384 })
  87. 385
  88. 386 50 130.0 2.6 1.0 if len(entity_name) == 0:
  89. 387 raise exceptions.IndexEmptyEntityIdError()
  90. 388
  91. 389 50 144.0 2.9 1.1 if len(fields) == 0:
  92. 390 raise exceptions.IndexInvalidEntityError()
  93. 391
  94. 392 100 281.0 2.8 2.2 for field_name, field_value in fields.items():
  95. 393 50 116.0 2.3 0.9 if field_name == 'entity-id':
  96. 394 raise exceptions.InvalidIndexationOnEntityIdFieldError(
  97. 395 more_info={
  98. 396 "entity": entity_name,
  99. 397 "msg": "The field \"entity-id\" is an internal field and "
  100. 398 "its value is based on indexed entity ID. "
  101. 399 "You are not allowed to index directly on it."
  102. 400 })
  103. 401
  104. 402 50 193.0 3.9 1.5 field = [_f for _f in fields_as if _f['api_name'] == field_name]
  105. 403
  106. 404 50 132.0 2.6 1.0 s1search_field_name = util.get_s1search_name(project_id, dimension,
  107. 405 50 190.0 3.8 1.5 field_name, test)
  108. 406 50 122.0 2.4 1.0 if not field:
  109. 407 field = util.check_field_cache(
  110. 408 project_id, dimension, s1search_field_name)
  111. 409 if not field:
  112. 410 LOGGER.info('Index field not active %s', field_name)
  113. 411 raise exceptions.IndexFieldNotActiveError(
  114. 412 more_info={'field-name': field_name})
  115. 413 else:
  116. 414 50 127.0 2.5 1.0 if not util.check_field_cache(
  117. 415 50 569.0 11.4 4.5 project_id, dimension, s1search_field_name):
  118. 416 1 4.0 4.0 0.0 util.add_field_cache(
  119. 417 1 31.0 31.0 0.2 project_id, dimension, s1search_field_name, field)
  120. 418 50 154.0 3.1 1.2 if isinstance(field_value, (list, tuple)):
  121. 419 for item in field_value:
  122. 420 if isinstance(field, list):
  123. 421 field_to_index = field[0]
  124. 422 else:
  125. 423 field_to_index = field
  126. 424 index.validate_field_param(field_to_index,
  127. 425 field_name, item)
  128. 426 else:
  129. 427 50 125.0 2.5 1.0 if isinstance(field, list):
  130. 428 50 128.0 2.6 1.0 field_to_index = field[0]
  131. 429 else:
  132. 430 field_to_index = field
  133. 431 index.validate_field_param(field_to_index,
  134. 432 field_name,
  135. 433 field_value)
  136. 434 50 225.0 4.5 1.8 field_uniq = [_f for _f in fields_as if _f['api_name'] == 'entity-id']
  137. 435
  138. 436 50 116.0 2.3 0.9 if entity_name in remaining_names:
  139. 437 index.validate_field_param(field_uniq[0], 'entity-id', entity_name)
  140. 438 1 2.0 2.0 0.0 return entity_ids
  141.  
  142.  
  143. Process finished with exit code 0
Add Comment
Please, Sign In to add comment