Skip to content

Switch from v1 to v2 lubrify functions#16

Merged
justin-sadakhom merged 4 commits intodevelopfrom
19177_switch-from-v-1-to-v-2-lubrify-functions
Mar 31, 2025
Merged

Switch from v1 to v2 lubrify functions#16
justin-sadakhom merged 4 commits intodevelopfrom
19177_switch-from-v-1-to-v-2-lubrify-functions

Conversation

@justin-sadakhom
Copy link
Copy Markdown
Member

@justin-sadakhom justin-sadakhom commented Mar 12, 2025

This change is necessary because we missed implementing pagination for releases in a previous story. It also includes some performance enhancements.

?.get(0)
?.releases

if (includeIssues) {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this skips the issues queries, if needed for performance reasons

Comment on lines +489 to +499
val issues = mutableSetOf<GetIssuesQuery.Issue>()
val numPages = ids.size / DEFAULT_PAGE_SIZE
val idsList = ids.toList()

for (i in 0..numPages) {
val query =
GetIssuesQuery(idsList.subList(i * DEFAULT_PAGE_SIZE, (i + 1) * DEFAULT_PAGE_SIZE))
val issuesInPage =
apolloClient.query(query).toFlow().single().data?.issues?.toSet() ?: emptySet()
issues.addAll(issuesInPage)
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

the ids need to be batched because the query can only handle 100 ids at a time

val childIssuesIds = mutableSetOf<String>()
var endCursor: String? = null
var hasNextPage: Boolean
fun getEpicsByIds(epicIds: List<String>): List<EpicData> = runBlocking {
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this change supports grabbing multiple epics in a single query, whereas before we'd have to do x queries for x epics

Comment on lines +499 to +517
val issues = mutableSetOf<GetIssuesQuery.Issue>()
val numPages = ids.size / DEFAULT_PAGE_SIZE
val idsList = ids.toList()

for (i in 0..numPages) {
val query =
GetIssuesQuery(
idsList
.stream()
.skip(i * DEFAULT_PAGE_SIZE.toLong())
.limit(DEFAULT_PAGE_SIZE.toLong())
.toList())

val issuesInPage =
apolloClient.query(query).toFlow().single().data?.issues?.toSet() ?: emptySet()
issues.addAll(issuesInPage)
}

issues
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

handles splitting ids into groups of 100 for the client, so client doesn't have to worry about pagination details and can just pass in the parameters hassle-free

Comment on lines +597 to +616

private fun handleQueryErrors(
error: com.apollographql.apollo3.api.Error,
epicIds: List<String>
) {
when (error.message) {
"Invalid global id: Make sure id is in Base64 format" -> {
throw IllegalArgumentException(error.message)
}

"Resource not found" -> {
val missingEpicIndex =
(error.path?.get(1) as? Int)
?: throw IllegalArgumentException("Value cannot be converted to Int")

throw IllegalArgumentException(
"Failed to retrieve epic with ID: ${epicIds[missingEpicIndex]}")
}
}
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

handles errors for the query that retrieves epics. I included this to provide more useful feedback to client if one of their ids causes a problem (wrong id format or id isn't tied to an epic). that way they can more easily troubleshoot problematic ids

@danielnstack8 danielnstack8 self-assigned this Mar 28, 2025
Copy link
Copy Markdown
Contributor

@danielnstack8 danielnstack8 left a comment

Choose a reason for hiding this comment

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

lgtm

@justin-sadakhom justin-sadakhom merged commit 1a98c96 into develop Mar 31, 2025
@justin-sadakhom justin-sadakhom deleted the 19177_switch-from-v-1-to-v-2-lubrify-functions branch March 31, 2025 15:20
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