Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/features/registry/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,28 @@ const resolveWriteAccess = async (

const resolveImageId = multiCacheMemoizee(
async (effectiveName: string, tx: Tx): Promise<number | undefined> => {
if (effectiveName.startsWith('v2/')) {
// Since the legacy image_location prefixes are not in use since 2018,
// and as a result the vast majority of the images atm use the new
// REGISTRY2_HOST/v2/<uuid> format, and since an exact match query is 100x
// faster than a `$endswith`,
// as an optimization we first try to find the image using
// an exact match optimistically assuming it has a REGISTRY2 url prefix,
// and then fallback to `$endswith` if the optimization doesn't return any result.
const exactMatchRegistry2Image = await api.resin.get({
resource: 'image',
passthrough: { req: permissions.rootRead, tx },
id: {
is_stored_at__image_location: `${REGISTRY2_HOST}/${effectiveName}`,
},
options: {
$select: 'id',
},
});
if (exactMatchRegistry2Image != null) {
return exactMatchRegistry2Image.id;
}
}
const [image] = await api.resin.get({
resource: 'image',
passthrough: { req: permissions.rootRead, tx },
Expand Down
Loading