Skip to content

Commit e6074f9

Browse files
committed
performance: cache %RoutineMgr:UserType results in PPG
1 parent bc7da6d commit e6074f9

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

cls/SourceControl/Git/Utils.cls

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -782,7 +782,7 @@ ClassMethod Type(InternalName As %String) As %String
782782
}
783783

784784
// For an abstract document, use the GetOther() method to try to determine its "real" class
785-
If ##class(%RoutineMgr).UserType(InternalName,.docclass,.doctype) {
785+
If ..UserTypeCached(InternalName,.docclass,.doctype) {
786786
// Check for a real abstract document subclass (or GetOther() may not work)
787787
If $classmethod(docclass,"%IsA","%Studio.AbstractDocument") && $classmethod(docclass,"%Extends","Ens.Util.AbstractDocument") {
788788
// Grab the actual name
@@ -1109,7 +1109,7 @@ ClassMethod ImportItem(InternalName As %String, force As %Boolean = 0, verbose A
11091109
#dim sc as %Status = $$$OK
11101110

11111111
if ..IsRoutineOutdated(InternalName) || force {
1112-
if ##class(%RoutineMgr).UserType(InternalName,.docclass,.doctype) {
1112+
if ..UserTypeCached(InternalName,.docclass,.doctype) {
11131113
set routineMgr = ##class(%RoutineMgr).%OpenId(InternalName)
11141114
do routineMgr.Code.Rewind()
11151115
set source = ##class(%Stream.FileCharacter).%OpenId(filename,,.sc)
@@ -1172,7 +1172,7 @@ ClassMethod ListItemsInFiles(ByRef itemList, ByRef err) As %Status
11721172
set mappedFilePath = ##class(%File).NormalizeFilename(mappedRelativePath, ..TempFolder())
11731173

11741174
if (##class(%File).DirectoryExists(mappedFilePath)){
1175-
if ##class(%Library.RoutineMgr).UserType("foo."_mappingFileType) {
1175+
if ..UserTypeCached("foo."_mappingFileType) {
11761176
set fileSpec = "*."_$zcvt(mappingFileType,"L")_";*."_$zconvert(mappingFileType,"U")
11771177
set files = ##class(%Library.File).FileSetFunc(mappedFilePath,fileSpec)
11781178
while files.%Next() {
@@ -1271,7 +1271,7 @@ ClassMethod ImportRoutines(force As %Boolean = 0) As %Status
12711271
if ##class(%File).Exists(filename) && '##class(%File).Delete(filename) {
12721272
set ec = $$$ADDSC(ec, ..MakeError("Error while removing "_item))
12731273
}
1274-
}elseif ##class(%Library.RoutineMgr).UserType(item) {
1274+
}elseif ..UserTypeCached(item) {
12751275
set ec = $$$ADDSC(ec, ##class(%Library.RoutineMgr).Delete(item))
12761276
} else {
12771277
set deleted = 0
@@ -1553,10 +1553,10 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
15531553
set relativePath = context.ResourceReference.Processor.OnItemRelativePath(InternalName)
15541554
quit relativePath
15551555
}
1556-
set usertype=$system.CLS.IsMthd("%Library.RoutineMgr","UserType")
15571556

15581557
// For an abstract document, use the GetOther() method to try to determine its "real" class
1559-
if usertype,##class(%RoutineMgr).UserType(InternalName,.docclass,.doctype) {
1558+
if ..UserTypeCached(InternalName,.docclass,.doctype) {
1559+
set usertype = 1
15601560
// Check for a real abstract document subclass (or GetOther() may not work)
15611561
if $classmethod(docclass,"%IsA","%Studio.AbstractDocument") && $classmethod(docclass,"%Extends","Ens.Util.AbstractDocument") {
15621562
// Grab the actual name
@@ -1664,6 +1664,31 @@ ClassMethod Name(InternalName As %String, ByRef MappingExists As %Boolean) As %S
16641664
}
16651665
}
16661666

1667+
/// Implementation copied from %Library.RoutineMgr, but with results cached in a PPG.
1668+
ClassMethod UserTypeCached(Name As %String, ByRef Class As %String, ByRef StudioType As %String, ByRef Schema As %String, ByRef StudioIcon As %Integer) As %Boolean
1669+
{
1670+
Set ext=$zconvert($piece(Name,".",*),"U") If ext="" Quit 0
1671+
If $Data(^||UserTypeCache(ext,"NotUserType"))#2 {
1672+
Quit 0
1673+
}
1674+
If $Data(^||UserTypeCache(ext),data)#2 {
1675+
Set Class = $Get(^||UserTypeCache(ext,"Class"))
1676+
Set StudioType=$list(data),Schema=$listget(data,3),StudioIcon=+$listget(data,4)
1677+
Quit 1
1678+
}
1679+
Do StudioDocument^%SYS.cspServer2(.document)
1680+
Set Class="",StudioType="",Schema=""
1681+
For Set Class=$order(document(Class)) Quit:Class=""||($data(document(Class,ext),data))
1682+
If Class="" {
1683+
Set ^||UserTypeCache(ext,"NotUserType") = 1
1684+
Quit 0
1685+
}
1686+
Set StudioType=$list(data),Schema=$listget(data,3),StudioIcon=+$listget(data,4)
1687+
Set ^||UserTypeCache(ext) = data
1688+
Set ^||UserTypeCache(ext,"Class") = Class
1689+
Quit 1
1690+
}
1691+
16671692
/*
16681693
NameToInternalName(name): given a Unix-style slash path relative to repo root,
16691694
returns the internal name for that file (e.g., cls/SourceControl/Git/Utils.cls -> SourceControl.Git.Utils.CLS)

0 commit comments

Comments
 (0)