Skip to content

Add an endpoint for image usages by supplier - #4879

Merged
junyuanxue merged 1 commit into
mainfrom
image-usages
Aug 19, 2026
Merged

Add an endpoint for image usages by supplier#4879
junyuanxue merged 1 commit into
mainfrom
image-usages

Conversation

@junyuanxue

@junyuanxue junyuanxue commented Aug 17, 2026

Copy link
Copy Markdown
Contributor

What does this change?

  • Adds an endpoint /usage/suppliers/:id/images, which returns a paginated list of images along with its relevant usages for each agency.

  • We only care about usages that are under published, unknown, and removed statuses for now, on digital and print platforms.

  • I've allowed for usage added date range to be passed in via search params to give us more flexibility around investigating various date ranges and compare against Kevin's RCS email, without being limited to the 'last 30 days' logic.

  • This endpoint would be extremely useful for providing some transparency around image usages as we investigate usage reporting in the Grid and quota counting from RCS.

How should a reviewer test this change?

{
  "offset": 0,
  "length": 73,
  "total": 73,
  "data": [
    {
      "id": "09f2c303a1b00697a092272156b4b149cb386354",
      "supplier": "Getty Images",
      "usages": [
        {
          "id": "front/34efed86f207c04264e9ee2ee2cb4bf4_d9a2c6f3b5c5d77d95dfdfd74b834ea3",
          "references": [
            {
              "type": "front",
              "name": "olly"
            }
          ],
          "platform": "digital",
          "media": "image",
          "status": "unknown",
          "dateAdded": "2023-04-27T14:29:21.150Z",
          "lastModified": "2023-04-27T14:29:21.150Z",
          "frontUsageMetadata": {
            "addedBy": "[email protected]",
            "front": "olly"
          }
        }
      ]
    },
    {
      "id": "0345c73bf81cafeb11ef8bc1ccc26ff2410a67f4",
      "supplier": "Getty Images",
      "usages": [
        {
          "id": "front/2b46ae683500c561863adfb0856324e_a3f8975262b7c4085f9d07aba3876f56",
          "references": [
            {
              "type": "front",
              "name": "uk"
            }
          ],
          "platform": "digital",
          "media": "image",
          "status": "unknown",
          "dateAdded": "2023-05-04T08:24:04.750Z",
          "lastModified": "2023-05-04T08:24:04.750Z",
          "frontUsageMetadata": {
            "addedBy": "[email protected]",
            "front": "uk"
          }
        }
      ]
    },
   // ...etc etc
  ]
}

Tested? Documented?

  • locally by committer
  • locally by Guardian reviewer
  • on the Guardian's TEST environment
  • relevant documentation added or amended (if needed)

@junyuanxue junyuanxue added the feature Departmental tracking: work on a new feature label Aug 17, 2026
@github-actions

github-actions Bot commented Aug 17, 2026

Copy link
Copy Markdown

@junyuanxue junyuanxue changed the title Add an endpoint for showing the usages and supplier of image ids Add an endpoint for image usages by supplier Aug 17, 2026
@junyuanxue
junyuanxue force-pushed the image-usages branch 3 times, most recently from 36f5cb4 to d8925be Compare August 19, 2026 11:07
@junyuanxue
junyuanxue marked this pull request as ready for review August 19, 2026 11:16
@junyuanxue
junyuanxue requested a review from a team as a code owner August 19, 2026 11:16
@junyuanxue
junyuanxue force-pushed the image-usages branch 4 times, most recently from 5f2b474 to 732441d Compare August 19, 2026 12:55

val query = boolQuery().must(matchAllQuery()).filter(boolQuery().must(beSupplier, haveQualifyingUsage))

val search = prepareSearch(query).trackTotalHits(true).from(offset).size(length)

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.

There is an upper bound to consider for elasticsearch pagination - beyond a certain limit performance drops off a cliff, so it might be good to sanitise the offset value unless that's taken care of elsewhere. See https://www.elastic.co/docs/reference/elasticsearch/rest-apis/paginate-search-results

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.

It might also be that you'll never get anywhere close to the limit in this context.

@junyuanxue junyuanxue Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Within the API endpoint I'm limiting length to the maxSize set in SearchParams which is 200. I could enforce this check within this function too

Edit: added :)

@junyuanxue junyuanxue Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry I misunderstood your point entirely! That's a useful callout for sure. I've tweaked how search params are validated and included that.

We don't seem to have that guard on the images search though, unless I'm missing something? Curious how we'd handle that 👀

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.

I'm not really familiar with Grid enough myself yet. If there is already some paging going on, then it's likely to be fine.

I just know that in CAPI we have to have a hard limit on how deeply we can page and it's waaay less that 10K. The change you've made sets the default cap limit but in practice the cluster's actual performance may dictate a lower value.

I'd have to defer all this to anyone who's closer to the code for the final approval. This was the only thing that caught my eye.

@junyuanxue junyuanxue Aug 19, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ah I think there is a hardcoded 10k check from the FE 😂
Screenshot 2026-08-19 at 16 25 13

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think a cursor-based pagination would bypass this problem. But I don't really want to introduce a new pattern. As this behaves pretty similarly as offset-based paginated image search, keeping the 10k limit seems to be the simple safeguard. Realistically we have ~6000 unique images for the highest-usage supplier in a 30-day window which is what we're interested in (the rest are more around or under 1000)

@hk-15 hk-15 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I have been playing around with this and as far as I can see it is all working as it should 🎉

@junyuanxue
junyuanxue force-pushed the image-usages branch 3 times, most recently from bc5498c to 6253922 Compare August 19, 2026 14:36
@gu-prout

gu-prout Bot commented Aug 19, 2026

Copy link
Copy Markdown

Overdue on auth, usage, image-loader, metadata-editor, thrall, leases, cropper, collections, media-api, kahuna (merged by @junyuanxue 30 minutes and 3 seconds ago) What's gone wrong?

@gu-prout

gu-prout Bot commented Aug 19, 2026

Copy link
Copy Markdown

Seen on auth, usage, image-loader, metadata-editor, thrall, leases, cropper, collections, media-api, kahuna (merged by @junyuanxue 51 minutes and 1 second ago) Please check your changes!

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants