-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improved
atVersion.supportedByAutomation
field handling (#1182)
* First attempt at cache, failing tests * Simplification getAtVersionWithRequirements * Import resolver by property name in AtVersion resolver
- Loading branch information
Showing
7 changed files
with
73 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
const supportedByAutomation = require('./supportedByAutomationResolver'); | ||
|
||
const AtVersion = { | ||
supportedByAutomation | ||
}; | ||
|
||
module.exports = AtVersion; |
16 changes: 16 additions & 0 deletions
16
server/resolvers/AtVersion/supportedByAutomationResolver.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
const { getAtVersionById } = require('../../models/services/AtService'); | ||
const { | ||
isSupportedByAutomation | ||
} = require('../../util/isSupportedByAutomation'); | ||
|
||
const supportedByAutomationResolver = async (parent, _, { transaction }) => { | ||
const atVersion = await getAtVersionById({ | ||
id: parent.id, | ||
transaction | ||
}); | ||
return isSupportedByAutomation(atVersion.at.id, atVersion.name, { | ||
transaction | ||
}); | ||
}; | ||
|
||
module.exports = supportedByAutomationResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const AtLoader = require('../models/loaders/AtLoader'); | ||
const { AT_VERSIONS_SUPPORTED_BY_COLLECTION_JOBS } = require('./constants'); | ||
|
||
let atIdToNameCache = {}; | ||
|
||
const isSupportedByAutomation = async function ( | ||
atId, | ||
versionName, | ||
{ transaction } | ||
) { | ||
if (Object.keys(atIdToNameCache).length === 0) { | ||
const ats = await AtLoader().getAll({ transaction }); | ||
for (const at of ats) { | ||
atIdToNameCache[at.id] = at.name; | ||
} | ||
} | ||
const atName = atIdToNameCache[atId]; | ||
if (!atName) { | ||
console.warn( | ||
`Attempt to check if ${versionName} is supported by automation for unknown AT ${atId}` | ||
); | ||
return false; | ||
} | ||
const supportedVersions = | ||
AT_VERSIONS_SUPPORTED_BY_COLLECTION_JOBS[atName] || []; | ||
const isSupported = supportedVersions.includes(versionName); | ||
return isSupported; | ||
}; | ||
|
||
module.exports = { isSupportedByAutomation }; |