Add last modified date to TestCase and TestPlan#4278
Add last modified date to TestCase and TestPlan#4278veenone wants to merge 1 commit intokiwitcms:masterfrom
Conversation
Display the last modified date on detail and search pages for both TestCase and TestPlan by querying the existing history records instead of adding a new model field. No migrations required.
1cfebfd to
481aaec
Compare
atodorov
left a comment
There was a problem hiding this comment.
Original approach is straight forward but will kill performance for large installations.
PR needs changes related to performance.
Please also split the changes for test case & test plan pages into 2 separate pull requests.
| TestCase.history.model.objects.filter(id=OuterRef("pk")) | ||
| .order_by("-history_date") | ||
| .values("history_date")[:1] | ||
| ), |
There was a problem hiding this comment.
This is a no-go!
A subquery will essentially make multiple extra queries which will have disastrous effects on performance. On a production dataset with 1684 test cases, which have 2806 historical record between all of them this results in a 2x worse performance!
We've got Kiwi TCMS installations with thousands of test cases where this query will kill the entire application.
There was a problem hiding this comment.
Try this instead (change what's the model we query and how we find what data to return):
- Add
test_case_ids = TestCase.objects.filter(**query).values("id")
- Replace
TestCase.objects->HistoricalTestCase.objects - The filter statement becomes
.filter(id__in=test_case_ids) - Add
history_datein the.values()argument list - Change the order/disctinct clause to
.order_by("id", "-history_date")
.distinct("id")
Which essentially means: get me the last available record of each test case which matches the query filter passed to this call and has not been removed.
Then display the "history_date" column with the title "Last modified".
There was a problem hiding this comment.
^^^ NOTE: the proposed approach above results in 1 extra query to fetch the relevant IDs.
implements #4140
Screenshots