Skip to content

Commit 4877a7d

Browse files
shashankbrgowdagarrettjstevens
authored andcommitted
fetch features by ids
1 parent 1b95bfe commit 4877a7d

File tree

6 files changed

+50
-7
lines changed

6 files changed

+50
-7
lines changed

packages/apollo-cli/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ $ npm install -g @apollo-annotation/cli
1616
$ apollo COMMAND
1717
running command...
1818
$ apollo (--version)
19-
@apollo-annotation/cli/0.3.9 linux-x64 node-v24.6.0
19+
@apollo-annotation/cli/0.3.9 darwin-x64 node-v20.19.0
2020
$ apollo --help [COMMAND]
2121
USAGE
2222
$ apollo COMMAND

packages/apollo-cli/src/commands/feature/get.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,9 @@ export default class Get extends BaseCommand<typeof Get> {
8686
start: number,
8787
end: number,
8888
): Promise<Response> {
89-
const url = new URL(localhostToAddress(`${address}/features/getFeatures`))
89+
const url = new URL(
90+
localhostToAddress(`${address}/features/getFeaturesByRange`),
91+
)
9092
const searchParams = new URLSearchParams({
9193
refSeq,
9294
start: start.toString(),

packages/apollo-collaboration-server/src/entity/gff3Object.dto.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,8 @@ export interface FeatureRangeSearchDto {
2828
start: number
2929
end: number
3030
}
31+
32+
export interface FeatureIdsSearchDto {
33+
featureIds: string[]
34+
topLevel?: boolean
35+
}

packages/apollo-collaboration-server/src/features/features.controller.ts

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
import {
2+
Body,
23
Controller,
34
Get,
45
Logger,
56
Param,
67
ParseBoolPipe,
8+
Post,
79
Query,
810
} from '@nestjs/common'
911

10-
import { FeatureRangeSearchDto } from '../entity/gff3Object.dto'
12+
import {
13+
FeatureIdsSearchDto,
14+
FeatureRangeSearchDto,
15+
} from '../entity/gff3Object.dto'
1116
import { Role } from '../utils/role/role.enum'
1217
import { Validations } from '../utils/validation/validatation.decorator'
1318

@@ -36,15 +41,26 @@ export class FeaturesController {
3641
* @returns Return 'HttpStatus.OK' and array of features if search was successful
3742
* or if search data was not found or in case of error throw exception
3843
*/
39-
@Get('getFeatures')
40-
getFeatures(@Query() request: FeatureRangeSearchDto) {
44+
@Get('getFeaturesByRange')
45+
getFeaturesByRange(@Query() request: FeatureRangeSearchDto) {
4146
this.logger.debug(
42-
`getFeaturesByCriteria -method: refSeq: ${request.refSeq}, start: ${request.start}, end: ${request.end}`,
47+
`getFeaturesByRange -method: refSeq: ${request.refSeq}, start: ${request.start}, end: ${request.end}`,
4348
)
4449

4550
return this.featuresService.findByRange(request)
4651
}
4752

53+
@Post('getFeatures')
54+
getFeatures(@Body() request: FeatureIdsSearchDto) {
55+
this.logger.debug(
56+
`getFeatures -method: featureIds: ${JSON.stringify(request.featureIds)}`,
57+
)
58+
return this.featuresService.findByFeatureIds(
59+
request.featureIds,
60+
request.topLevel,
61+
)
62+
}
63+
4864
@Get('count')
4965
async getFeatureCount(@Query() featureCountRequest: FeatureCountRequest) {
5066
this.logger.debug(

packages/apollo-collaboration-server/src/features/features.service.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,26 @@ export class FeaturesService {
117117
return
118118
}
119119

120+
async findByFeatureIds(featureIds: string[], topLevel?: boolean) {
121+
const foundFeatures: Feature[] = []
122+
// all featureIds that have already been fetched
123+
const fetchedFeatureIds = new Set<string>()
124+
125+
for (const featureId of featureIds) {
126+
if (fetchedFeatureIds.has(featureId)) {
127+
this.logger.debug(`FeatureId ${featureId} already fetched, skipping...`)
128+
continue
129+
}
130+
const feature = await this.findById(featureId, topLevel)
131+
foundFeatures.push(feature)
132+
133+
for (const id of feature.allIds) {
134+
fetchedFeatureIds.add(id)
135+
}
136+
}
137+
return foundFeatures
138+
}
139+
120140
/**
121141
* Get feature by featureId. When retrieving features by id, the features and any of its children are returned, but not any of its parent or sibling features.
122142
* @param featureId - featureId

packages/jbrowse-plugin-apollo/src/BackendDrivers/CollaborationServerDriver.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export class CollaborationServerDriver extends BackendDriver {
119119
) as ApolloInternetAccount
120120
const { baseURL } = internetAccount
121121

122-
const url = new URL('features/getFeatures', baseURL)
122+
const url = new URL('features/getFeaturesByRange', baseURL)
123123
const searchParams = new URLSearchParams({
124124
refSeq,
125125
start: String(start),

0 commit comments

Comments
 (0)