File tree Expand file tree Collapse file tree 9 files changed +34
-0
lines changed Expand file tree Collapse file tree 9 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -5,6 +5,9 @@ import Signature from './Signature';
55
66export default ( config : FacadeConfig ) : Signature => {
77 return async ( { client, ids } ) => {
8+ if ( ids . length === 0 ) {
9+ return [ ] ;
10+ }
811 const filteredModels = config . state . statements . filter ( ( model ) => {
912 return (
1013 includes ( ids , model . statement . id ) &&
Original file line number Diff line number Diff line change @@ -11,6 +11,9 @@ interface Result {
1111
1212export default ( config : FacadeConfig ) : Signature => {
1313 return async ( { client, ids } ) => {
14+ if ( ids . length === 0 ) {
15+ return [ ] ;
16+ }
1417 const collection = ( await config . db ( ) ) . collection ( STATEMENTS_COLLECTION_NAME ) ;
1518
1619 const query = {
Original file line number Diff line number Diff line change @@ -16,6 +16,9 @@ const getTargetId = (model: StoredStatementModel) => {
1616
1717export default ( config : FacadeConfig ) : Signature => {
1818 return async ( { client, targetIds } ) => {
19+ if ( targetIds . length === 0 ) {
20+ return [ ] ;
21+ }
1922 const filteredModels = config . state . statements . filter ( ( model ) => {
2023 return (
2124 model . statement . object . objectType === 'StatementRef' &&
Original file line number Diff line number Diff line change @@ -14,6 +14,9 @@ interface Result {
1414
1515export default ( config : FacadeConfig ) : Signature => {
1616 return async ( { client, targetIds } ) => {
17+ if ( targetIds . length === 0 ) {
18+ return [ ] ;
19+ }
1720 const collection = ( await config . db ( ) ) . collection ( STATEMENTS_COLLECTION_NAME ) ;
1821
1922 const query = {
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ import Signature from './Signature';
77
88export default ( config : FacadeConfig ) : Signature => {
99 return async ( { client, ids } ) => {
10+ // istanbul ignore next - this is checked higher in the code.
11+ if ( ids . length === 0 ) {
12+ return [ ] ;
13+ }
1014 const query = ( statement : Statement ) => {
1115 return (
1216 statement . verb . id === voidVerbId &&
Original file line number Diff line number Diff line change @@ -7,6 +7,10 @@ interface Result { readonly statement: { readonly id: string }; }
77
88export default ( config : FacadeConfig ) : Signature => {
99 return async ( { client, ids } ) => {
10+ // istanbul ignore next - this is checked higher in the code.
11+ if ( ids . length === 0 ) {
12+ return [ ] ;
13+ }
1014 const query = {
1115 'statement.id' : { $in : ids } ,
1216 ...voidQuery ,
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ import Signature from './Signature';
88
99export default ( config : FacadeConfig ) : Signature => {
1010 return async ( { client, ids } ) => {
11+ if ( ids . length === 0 ) {
12+ return [ ] ;
13+ }
1114 const query = ( statement : Statement ) => {
1215 return (
1316 statement . verb . id === voidVerbId &&
Original file line number Diff line number Diff line change @@ -7,6 +7,9 @@ interface Result { readonly statement: { readonly object: { readonly id: string
77
88export default ( config : FacadeConfig ) : Signature => {
99 return async ( { client, ids } ) => {
10+ if ( ids . length === 0 ) {
11+ return [ ] ;
12+ }
1013 const query = {
1114 'statement.object.id' : { $in : ids } ,
1215 ...voidQuery ,
Original file line number Diff line number Diff line change @@ -30,6 +30,14 @@ describe('get statement', () => {
3030 assertNoStatements ( actualStatements as Statement [ ] ) ;
3131 } ) ;
3232
33+ it ( 'should ensure that we do not make unnecessary database queries for refs' , async ( ) => {
34+ await storeStatements ( [ {
35+ actor : { mbox : 'mailto:test@example.org' } ,
36+ verb : { id : 'https://example.org/verb' } ,
37+ object : { id : 'https://example.org/activity' } ,
38+ } ] ) ;
39+ } ) ;
40+
3341 it ( 'should throw an error when the store does not match' , async ( ) => {
3442 const unknownClient = createClientModel ( {
3543 lrs_id : '5988ff000000000000000001' ,
You can’t perform that action at this time.
0 commit comments