-
Notifications
You must be signed in to change notification settings - Fork 15k
Added last_asset_event_id
and last_asset_event_timestamp
to the AssetResponse
#50060
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
@pierrejeambrun, @bbovenzi, #49994 closed in favor of this PR. |
AssetEvent.asset_id, # The ID of the Asset, which we'll need to JOIN to the AssetModel | ||
func.max(AssetEvent.id).label("last_asset_event_id"), # The ID of the last AssetEvent | ||
func.max(AssetEvent.timestamp).label("last_asset_event_timestamp"), | ||
) | ||
.group_by(AssetEvent.asset_id) | ||
.subquery() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure we're actually selecting the latest timestamp here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you clarify that a bit more? Is the thought here that the max AssetEvent.id
might not have the latest timestamp?
There is a unit-test validating this - would you just approach this with a self-JOIN?
…f max(AssetEvent.id) has the max(AssetEvent.timestamp)
This pull request adds the
last_asset_event_id
andlast_asset_event_timestamp
fields to theAssetResponse
model, and thus, the/assets
endpoint. The original use-case was to make the Asset list view sortable by the last Asset Event. However, there is a much larger use-case at play here; the ability to easily determine the timestamp for the last Asset Event for a certain Asset. This is especially applicable for Asset Watchers.By default, the
last_asset_event_id
andlast_asset_event_timestamp
fields are returned asnull
. It's not until the first Asset Event that these fields are populated.Unit-tests were added/updated for all changes made.
related: #47164