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

Support snapshot pagination #547

Merged
merged 2 commits into from
Oct 5, 2023

Conversation

jamessalvatore
Copy link
Contributor

Description

Support limit and offset query parameters in the getFlagSnapshots API.

Motivation and Context

This change allows flag snapshots to be retrieved from the API using pagination, so you don't have to fetch all snapshots at once which can be slow for flags with many snapshots.

How Has This Been Tested?

Tested locally that the API is backwards compatible, such that it retrieves all snapshots when the query parameters are omitted:

curl http://localhost:18000/api/v1/flags/1/snapshots
[
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": false,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:51.882-04:00",
      "variants": []
    },
    "id": 3,
    "updatedAt": "2023-10-04T20:55:51Z"
  },
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": true,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:43.463-04:00",
      "variants": []
    },
    "id": 2,
    "updatedAt": "2023-10-04T20:55:43Z"
  },
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": false,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:38.469-04:00",
      "variants": []
    },
    "id": 1,
    "updatedAt": "2023-10-04T20:55:38Z"
  }
]

Tested locally that the new parameters worked:

curl http://localhost:18000/api/v1/flags/1/snapshots\?limit\=1
[
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": false,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:51.882-04:00",
      "variants": []
    },
    "id": 3,
    "updatedAt": "2023-10-04T20:55:51Z"
  }
]
curl http://localhost:18000/api/v1/flags/1/snapshots\?limit\=2\&offset\=1
[
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": true,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:43.463-04:00",
      "variants": []
    },
    "id": 2,
    "updatedAt": "2023-10-04T20:55:43Z"
  },
  {
    "flag": {
      "dataRecordsEnabled": false,
      "description": "test",
      "enabled": false,
      "id": 1,
      "key": "kgemgm1zhty1431sp",
      "segments": [],
      "tags": [],
      "updatedAt": "2023-10-04T16:55:38.469-04:00",
      "variants": []
    },
    "id": 1,
    "updatedAt": "2023-10-04T20:55:38Z"
  }
]

Additionally, unit tests were added for the new functionality.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

@ghost
Copy link

ghost commented Oct 4, 2023

👇 Click on the image for a new way to code review

Review these changes using an interactive CodeSee Map

Legend

CodeSee Map legend

@marceloboeira marceloboeira merged commit 1153f03 into openflagr:main Oct 5, 2023
9 checks passed
@marceloboeira
Copy link
Member

Thank you @jamessalvatore for the contribution!

@jamessalvatore
Copy link
Contributor Author

Hi @marceloboeira , thank you for merging this! When would it be possible to create a new release that includes this change?

@marceloboeira
Copy link
Member

Let me check and get back to you. In theory, if you use the latest docker image (or the commit reference) you could already use it.

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.

None yet

2 participants