Skip to content

Commit

Permalink
Merge pull request #568 from WolframResearch/bugfix/avoid-unnecessary…
Browse files Browse the repository at this point in the history
…-autoloads-in-dynamics

Prevent unnecessary autoloading when reading persona files
  • Loading branch information
rhennigan authored Jan 24, 2024
2 parents 02e8fb8 + db5e8c8 commit 555e54c
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions Source/Chatbook/ResourceInstaller.wl
Original file line number Diff line number Diff line change
Expand Up @@ -712,32 +712,36 @@ getInstalledResourceData[ rtype_ ] :=
];

getInstalledResourceData[ rtype: $$installableType ] := Enclose[
Module[ { data },
Module[ { tempHold, data, held, merged, released },
tempHold // Attributes = { Temporary, HoldAllComplete };
data = ConfirmMatch[ getInstalledResources @ rtype, { ___Association }, "GetInstalledResources" ];
Block[ { TemplateObject, CloudObject },
SetAttributes[ TemplateObject, HoldAllComplete ];
$installedResourceCache[ rtype ] = KeySort @ Association @ Cases[
data,
KeyValuePattern @ {
"Name" -> name_String,
"Configuration" -> config_Association,
"ResourceInformation" -> resourceAssoc_Association
} :>
name -> Merge[
{
config,
KeyDrop[ resourceAssoc, "Name" ],
<|
"Name" -> name,
"ResourceType" -> rtype,
"ResourceName" -> Lookup[ resourceAssoc, "Name", name ],
"Origin" -> determineOrigin[ rtype, resourceAssoc ]
|>
},
First
]
]
]
held = data /. expr: Except[ _List | _Association | _String | _Symbol ] :> tempHold @ expr;

merged = KeySort @ Association @ Cases[
held,
KeyValuePattern @ {
"Name" -> name_String,
"Configuration" -> config_Association,
"ResourceInformation" -> resourceAssoc_Association
} :>
name -> Merge[
{
config,
KeyDrop[ resourceAssoc, "Name" ],
<|
"Name" -> name,
"ResourceType" -> rtype,
"ResourceName" -> Lookup[ resourceAssoc, "Name", name ],
"Origin" -> determineOrigin[ rtype, resourceAssoc ]
|>
},
First
]
];

released = ConfirmBy[ merged /. tempHold[ expr_ ] :> expr, FreeQ @ tempHold, "Release" ];

$installedResourceCache[ rtype ] = released
],
throwInternalFailure[ getInstalledResourceData @ rtype, ## ] &
];
Expand Down

0 comments on commit 555e54c

Please sign in to comment.