Skip to content
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

Query for correct "latest" version #8

Open
Haroenv opened this issue May 20, 2018 · 1 comment
Open

Query for correct "latest" version #8

Haroenv opened this issue May 20, 2018 · 1 comment

Comments

@Haroenv
Copy link
Collaborator

Haroenv commented May 20, 2018

The version we display now is not always the latest version; see for example:

Most versions aren't the correct one

The query we are using now is:

WITH latest_version AS (
SELECT id, pod_id FROM (
SELECT
id,
pod_id,
rank() OVER (PARTITION by pod_id ORDER BY created_at desc) AS version_rank
FROM pod_versions
) AS ranked_versions
WHERE version_rank = 1
)
SELECT
pods.normalized_name AS "objectID",
commits.specification_data AS "specificationData",
json_build_object(
'lastMonth', stats_metrics.download_month,
'total', stats_metrics.download_total,
'appsTouched', stats_metrics.app_total
) AS downloads
FROM pods
LEFT JOIN latest_version ON latest_version.pod_id = pods.id
LEFT JOIN stats_metrics ON stats_metrics.pod_id = pods.id
LEFT JOIN commits ON commits.pod_version_id = latest_version.id

@orta
Copy link
Member

orta commented May 20, 2018

Could be inverse?

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

No branches or pull requests

2 participants