Skip to content

Add last modified date to TestCase and TestPlan#4278

Open
veenone wants to merge 1 commit intokiwitcms:masterfrom
veenone:feat/add-modified-date
Open

Add last modified date to TestCase and TestPlan#4278
veenone wants to merge 1 commit intokiwitcms:masterfrom
veenone:feat/add-modified-date

Conversation

@veenone
Copy link
Copy Markdown

@veenone veenone commented Feb 18, 2026

  • Add updated_at field to both models with migrations.
  • Show last modified date in detail view sidebars and search result tables.
  • Expose updated_at via RPC API filter and update responses.
  • If the entry never been modified yet, use created date on the modified date

implements #4140


Screenshots

image opera_n4Krs0xbOt opera_NJvRzpuVii opera_bTBkccZ3eD

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.
@veenone veenone force-pushed the feat/add-modified-date branch from 1cfebfd to 481aaec Compare February 26, 2026 16:14
Copy link
Copy Markdown
Member

@atodorov atodorov left a comment

Choose a reason for hiding this comment

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

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]
),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Try this instead (change what's the model we query and how we find what data to return):

  1. Add
test_case_ids = TestCase.objects.filter(**query).values("id")
  1. Replace TestCase.objects -> HistoricalTestCase.objects
  2. The filter statement becomes .filter(id__in=test_case_ids)
  3. Add history_date in the .values() argument list
  4. 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".

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

^^^ NOTE: the proposed approach above results in 1 extra query to fetch the relevant IDs.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants