Skip to content

Conversation

@marco-lengua
Copy link

This pull-request introduces a Document Service for document loading, so that the initialized document object persists across controllers. It adresses the current state issue, that every plugin controller (that implements AbstractController) loads the current document, initializes it and once the controller finishes it is deconstructed.
Every consecutive controller needs to load and initialize the document again.
This solution reuses the loaded document for the whole request and significantly optimizes execution time:

  • 5000 Page Adressbuch loads one-time for about 0.5 Seconds in the first controller and then loading is nearly instantly.
  • without this change each controller takes 0.5 seconds (chaining for example 6 controllers -e.g. detail view with PageGrid,PageView, ToC, Navigation, Toolbox, Metadata - leads to a loading time of about 3 seconds).
  • in this case the change improves execution time by a factor of 6.

Eventually it is required to flush all cashes in Admin->Maintainance so the dependency injection cache is cleared.

@sebastian-meyer sebastian-meyer added the ↷ feature A new feature or enhancement. label Dec 17, 2025
Copy link
Member

@sebastian-meyer sebastian-meyer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for your contribution and welcome to Kitodo! ;o)

Please see my comments below.

In general, please add (or restore) phpDoc where necessary according to the Coding Guidelines.

Also, maybe I am missing something, but wouldn't the DocumentService have to be a singleton in order for every controller to query the same instance? And how does this work when instantiating multiple documents (like for the BasketController or the new MultiView feature?

@marco-lengua
Copy link
Author

The Service Type is recommended since Typo3 Version 12 and Singletons are considered obsolete this is why we chose this pattern.
Singletons Typo3 V12.
In practice for one request cycle they behave the same as singletons. One instance persists for one request lifecycle across all controllers. If we would like to further extend the loading of a document to be available over more than one request we recommend using the cache, but that would be another pull request.
The Service does not change the controllers loading behaviour as it is now. The Basket Controller or even multiview still work the same.

autowire: false

Kitodo\Dlf\Service\DocumentService:
public: true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
public: true
public: true

Comment on lines 71 to 72
}
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
/**
}
/**

Comment on lines 58 to 59
}
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
/**
}
/**

Comment on lines 55 to 56
}
protected function reset()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
protected function reset()
}
protected function reset()

Comment on lines 46 to 47
protected DocumentRepository $documentRepository;
public function injectDocumentRepository(DocumentRepository $documentRepository): void
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
protected DocumentRepository $documentRepository;
public function injectDocumentRepository(DocumentRepository $documentRepository): void
protected DocumentRepository $documentRepository;
public function injectDocumentRepository(DocumentRepository $documentRepository): void

*
* @param string $documentId The document's UID or URL (id), fallback: record ID (recordId)
*
* @param string $documentId
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove the full documentation of this parameter?

public function injectDocumentService(DocumentService $documentService): void
{
$this->documentService = $documentService;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
}

Comment on lines 60 to 63
* @access public
* @param int $recordId
* @param array $settings
* @return ?Document
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please complete PHPDoc with short description of parameters and method.

Comment on lines 73 to 76
* @access public
* @param string $documentId
* @param int $recordId
* @param array $settings
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please complete PHPDoc with short description of parameters and method.

Comment on lines 116 to 117
}
/**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
}
/**
}
/**

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

↷ feature A new feature or enhancement.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants