comparison OrthancServer/Sources/ResourceFinder.cpp @ 5693:023787ecaff2 find-refactoring

cont
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 11 Jul 2024 21:37:20 +0200
parents 7c11a71927a9
children 4a85ee2cbe1f
comparison
equal deleted inserted replaced
5692:7c11a71927a9 5693:023787ecaff2
423 423
424 424
425 void ResourceFinder::UpdateRequestLimits() 425 void ResourceFinder::UpdateRequestLimits()
426 { 426 {
427 // By default, use manual paging 427 // By default, use manual paging
428 isDatabasePaging_ = false; 428 pagingMode_ = PagingMode_FullManual;
429 429
430 if (databaseLimits_ != 0) 430 if (databaseLimits_ != 0)
431 { 431 {
432 request_.SetLimits(0, databaseLimits_ + 1); 432 request_.SetLimits(0, databaseLimits_ + 1);
433 } 433 }
434 else 434 else
435 { 435 {
436 request_.ClearLimits(); 436 request_.ClearLimits();
437 } 437 }
438 438
439 if (hasLimits_) 439 if (lookup_.get() == NULL &&
440 { 440 (hasLimitsSince_ || hasLimitsCount_))
441 if (lookup_.get() == NULL) 441 {
442 { 442 pagingMode_ = PagingMode_FullDatabase;
443 isDatabasePaging_ = true; 443 request_.SetLimits(limitsSince_, limitsCount_);
444 request_.SetLimits(limitsSince_, limitsCount_); 444 }
445 } 445
446 446 if (lookup_.get() != NULL &&
447 // TODO-FIND: enable database paging on "simple" lookups that involve no normalization 447 isSimpleLookup_ &&
448 (hasLimitsSince_ || hasLimitsCount_))
449 {
450 /**
451 * TODO-FIND: "IDatabaseWrapper::ApplyLookupResources()" only
452 * accept the "limit" argument. The "since" must be implemented
453 * manually.
454 **/
455
456 if (hasLimitsSince_ &&
457 limitsSince_ != 0)
458 {
459 pagingMode_ = PagingMode_ManualSkip;
460 request_.SetLimits(0, limitsCount_ + limitsSince_);
461 }
462 else
463 {
464 pagingMode_ = PagingMode_FullDatabase;
465 request_.SetLimits(0, limitsCount_);
466 }
448 } 467 }
449 468
450 // TODO-FIND: More cases could be added, depending on "GetDatabaseCapabilities()" 469 // TODO-FIND: More cases could be added, depending on "GetDatabaseCapabilities()"
451 } 470 }
452 471
453 472
454 ResourceFinder::ResourceFinder(ResourceType level, 473 ResourceFinder::ResourceFinder(ResourceType level,
455 bool expand) : 474 bool expand) :
456 request_(level), 475 request_(level),
457 databaseLimits_(0), 476 databaseLimits_(0),
458 isDatabasePaging_(true), 477 isSimpleLookup_(true),
459 hasLimits_(false), 478 pagingMode_(PagingMode_FullManual),
479 hasLimitsSince_(false),
480 hasLimitsCount_(false),
460 limitsSince_(0), 481 limitsSince_(0),
461 limitsCount_(0), 482 limitsCount_(0),
462 expand_(expand), 483 expand_(expand),
463 format_(DicomToJsonFormat_Human), 484 format_(DicomToJsonFormat_Human),
464 allowStorageAccess_(true), 485 allowStorageAccess_(true),
507 databaseLimits_ = limits; 528 databaseLimits_ = limits;
508 UpdateRequestLimits(); 529 UpdateRequestLimits();
509 } 530 }
510 531
511 532
512 void ResourceFinder::SetLimits(uint64_t since, 533 void ResourceFinder::SetLimitsSince(uint64_t since)
513 uint64_t count) 534 {
514 { 535 if (hasLimitsSince_)
515 if (hasLimits_)
516 { 536 {
517 throw OrthancException(ErrorCode_BadSequenceOfCalls); 537 throw OrthancException(ErrorCode_BadSequenceOfCalls);
518 } 538 }
519 else 539 else
520 { 540 {
521 hasLimits_ = true; 541 hasLimitsSince_ = true;
522 limitsSince_ = since; 542 limitsSince_ = since;
543 UpdateRequestLimits();
544 }
545 }
546
547
548 void ResourceFinder::SetLimitsCount(uint64_t count)
549 {
550 if (hasLimitsCount_)
551 {
552 throw OrthancException(ErrorCode_BadSequenceOfCalls);
553 }
554 else
555 {
556 hasLimitsCount_ = true;
523 limitsCount_ = count; 557 limitsCount_ = count;
524 UpdateRequestLimits(); 558 UpdateRequestLimits();
525 } 559 }
526 } 560 }
527 561
538 AddRequestedTag(tag); 572 AddRequestedTag(tag);
539 } 573 }
540 } 574 }
541 575
542 MainDicomTagsRegistry registry; 576 MainDicomTagsRegistry registry;
543 registry.NormalizeLookup(request_.GetDicomTagConstraints(), lookup, request_.GetLevel()); 577 isSimpleLookup_ = registry.NormalizeLookup(request_.GetDicomTagConstraints(), lookup, request_.GetLevel());
544 578
545 // "request_.GetDicomTagConstraints()" only contains constraints on main DICOM tags 579 // "request_.GetDicomTagConstraints()" only contains constraints on main DICOM tags
546 580
547 for (size_t i = 0; i < request_.GetDicomTagConstraints().GetSize(); i++) 581 for (size_t i = 0; i < request_.GetDicomTagConstraints().GetSize(); i++)
548 { 582 {
833 { 867 {
834 FindResponse response; 868 FindResponse response;
835 context.GetIndex().ExecuteFind(response, request_); 869 context.GetIndex().ExecuteFind(response, request_);
836 870
837 bool complete; 871 bool complete;
838 if (isDatabasePaging_) 872
839 { 873 switch (pagingMode_)
840 complete = true; 874 {
841 } 875 case PagingMode_FullDatabase:
842 else 876 case PagingMode_ManualSkip:
843 { 877 complete = true;
844 complete = (databaseLimits_ == 0 || 878 break;
845 response.GetSize() <= databaseLimits_); 879
880 case PagingMode_FullManual:
881 complete = (databaseLimits_ == 0 ||
882 response.GetSize() <= databaseLimits_);
883 break;
884
885 default:
886 throw OrthancException(ErrorCode_InternalError);
846 } 887 }
847 888
848 if (lookup_.get() != NULL) 889 if (lookup_.get() != NULL)
849 { 890 {
850 LOG(INFO) << "Number of candidate resources after fast DB filtering on main DICOM tags: " << response.GetSize(); 891 LOG(INFO) << "Number of candidate resources after fast DB filtering on main DICOM tags: " << response.GetSize();
893 match = lookup_->IsMatch(tags); 934 match = lookup_->IsMatch(tags);
894 } 935 }
895 936
896 if (match) 937 if (match)
897 { 938 {
898 if (isDatabasePaging_) 939 if (pagingMode_ == PagingMode_FullDatabase)
899 { 940 {
900 visitor.Apply(resource, hasRequestedTags_, requestedTags); 941 visitor.Apply(resource, hasRequestedTags_, requestedTags);
901 } 942 }
902 else 943 else
903 { 944 {
904 if (hasLimits_ && 945 if (hasLimitsSince_ &&
905 skipped < limitsSince_) 946 skipped < limitsSince_)
906 { 947 {
907 skipped++; 948 skipped++;
908 } 949 }
909 else if (hasLimits_ && 950 else if (hasLimitsCount_ &&
910 countResults >= limitsCount_) 951 countResults >= limitsCount_)
911 { 952 {
912 // Too many results, don't mark as complete 953 // Too many results, don't mark as complete
913 complete = false; 954 complete = false;
914 break; 955 break;