mirror of
https://github.com/danieleteti/delphimvcframework.git
synced 2024-11-15 07:45:54 +01:00
Optimized pooling and cache of frequently used object in mustache and partitioning
This commit is contained in:
parent
d4c7e449ae
commit
d1b14eb24a
@ -4486,6 +4486,12 @@ begin
|
||||
}
|
||||
if not PartitionInfoCache.TryGetValue(PartitionClause + '|' + RQLCompilerClass.ClassName, Result) then
|
||||
begin
|
||||
TMonitor.Enter(PartitionInfoCache);
|
||||
try
|
||||
if PartitionInfoCache.TryGetValue(PartitionClause + '|' + RQLCompilerClass.ClassName, Result) then
|
||||
begin
|
||||
Exit;
|
||||
end;
|
||||
lRQLCompiler := RQLCompilerClass.Create(nil);
|
||||
try
|
||||
Result := TPartitionInfo.Create;
|
||||
@ -4523,6 +4529,9 @@ begin
|
||||
finally
|
||||
lRQLCompiler.Free;
|
||||
end;
|
||||
finally
|
||||
TMonitor.Exit(PartitionInfoCache);
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
|
||||
|
@ -32,7 +32,7 @@ interface
|
||||
uses
|
||||
MVCFramework, System.SysUtils, System.Generics.Collections,
|
||||
MVCFramework.Commons, System.IOUtils, System.RTTI,
|
||||
System.Classes, Data.DB, SynMustache, SynCommons;
|
||||
System.Classes, Data.DB, SynMustache, SynCommons, MVCFramework.IntfObjectPool;
|
||||
|
||||
type
|
||||
{ This class implements the mustache view engine for server side views }
|
||||
@ -42,6 +42,7 @@ type
|
||||
private
|
||||
class var fPartials: TSynMustachePartials;
|
||||
class var fHelpers: TSynMustacheHelpers;
|
||||
class var fSerializerPool: IIntfObjectPool;
|
||||
var FJSONModelAsString: string;
|
||||
procedure LoadPartials;
|
||||
procedure LoadHelpers;
|
||||
@ -55,6 +56,7 @@ type
|
||||
const AViewDataSets: TObjectDictionary<string, TDataSet>;
|
||||
const AContentType: string); override;
|
||||
class destructor Destroy;
|
||||
class constructor Create;
|
||||
end;
|
||||
|
||||
TLoadCustomHelpersProc = reference to procedure(var MustacheHelpers: TSynMustacheHelpers);
|
||||
@ -107,6 +109,16 @@ begin
|
||||
LoadHelpers;
|
||||
end;
|
||||
|
||||
class constructor TMVCMustacheViewEngine.Create;
|
||||
begin
|
||||
fSerializerPool := MVCFramework.IntfObjectPool.TIntfObjectPool.Create(10000, 10,1,
|
||||
function: IInterface
|
||||
begin
|
||||
Result := TMVCJsonDataObjectsSerializer.Create(nil);
|
||||
RegisterOptionalCustomTypesSerializers(Result as IMVCSerializer);
|
||||
end);
|
||||
end;
|
||||
|
||||
class destructor TMVCMustacheViewEngine.Destroy;
|
||||
begin
|
||||
fPartials.Free;
|
||||
@ -207,7 +219,7 @@ procedure TMVCMustacheViewEngine.PrepareModels;
|
||||
var
|
||||
DataObj: TPair<string, TValue>;
|
||||
lDSPair: TPair<string, TDataSet>;
|
||||
lSer: TMVCJsonDataObjectsSerializer;
|
||||
lSer: IMVCSerializer;
|
||||
lJSONModel: TJsonObject;
|
||||
begin
|
||||
if Assigned(FJSONModel) and (not Assigned(ViewModel)) and (not Assigned(ViewDataSets)) then
|
||||
@ -217,9 +229,10 @@ begin
|
||||
Exit;
|
||||
end;
|
||||
|
||||
lSer := TMVCJsonDataObjectsSerializer.Create;
|
||||
|
||||
|
||||
lSer := fSerializerPool.GetFromPool(True) as IMVCSerializer;
|
||||
try
|
||||
RegisterOptionalCustomTypesSerializers(lSer);
|
||||
if Assigned(FJSONModel) then
|
||||
begin
|
||||
lJSONModel := FJSONModel.Clone as TJsonObject;
|
||||
@ -233,7 +246,7 @@ begin
|
||||
begin
|
||||
for DataObj in ViewModel do
|
||||
begin
|
||||
lSer.TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil);
|
||||
TMVCJsonDataObjectsSerializer(lSer).TValueToJSONObjectProperty(lJSONModel, DataObj.Key, DataObj.Value, TMVCSerializationType.stDefault, nil, nil);
|
||||
// lList := TDuckTypedList.Wrap(DataObj.Value);
|
||||
// if lList <> nil then
|
||||
// begin
|
||||
@ -250,7 +263,7 @@ begin
|
||||
begin
|
||||
for lDSPair in ViewDataSets do
|
||||
begin
|
||||
lSer.DataSetToJsonArray(lDSPair.Value, lJSONModel.A[lDSPair.Key], TMVCNameCase.ncAsIs, nil);
|
||||
TMVCJsonDataObjectsSerializer(lSer).DataSetToJsonArray(lDSPair.Value, lJSONModel.A[lDSPair.Key], TMVCNameCase.ncAsIs, nil);
|
||||
end;
|
||||
end;
|
||||
FJSONModelAsString := lJSONModel.ToJSON(False);
|
||||
@ -258,7 +271,7 @@ begin
|
||||
lJSONModel.Free;
|
||||
end;
|
||||
finally
|
||||
lSer.Free;
|
||||
fSerializerPool.ReleaseToPool(lSer)
|
||||
end;
|
||||
end;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user