Skip to content

Commit aa998e8

Browse files
authored
Feature/serialzer cache (#244)
* feat: cache smart cache on serializers Change-Id: I0d0994bf1da352a7a3b0d5a8427a379ce78cf56a * fix: expand relations on events related serializers Signed-off-by: [email protected] <[email protected]> Change-Id: Ifbd7abbb73ff7be2a280768710df5e45a99c80fc * refactor: add serializer decorator for params pre processing refactor: removed unused code fix: add relation and field usage over all serializers Change-Id: If3903f5965535fb792babe4c79bc570a07b633d9 * fix: added validation exception Change-Id: I9bb93caf91b909c611de813ca4af49300590cffa --------- Signed-off-by: [email protected] <[email protected]>
1 parent 2bf17cc commit aa998e8

File tree

160 files changed

+1478
-558
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

160 files changed

+1478
-558
lines changed

Libs/ModelSerializers/AbstractSerializer.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ public function __construct($object, IResourceServerContext $resource_server_con
5050
$this->resource_server_context = $resource_server_context;
5151
}
5252

53-
protected static $array_mappings = [
54-
];
53+
protected static $array_mappings = [];
5554

5655
protected static $allowed_fields = [];
5756

@@ -62,7 +61,7 @@ public function __construct($object, IResourceServerContext $resource_server_con
6261
/**
6362
* @return array
6463
*/
65-
protected function getAllowedFields():array
64+
public function getAllowedFields():array
6665
{
6766
try {
6867
$allowed_fields = [];
@@ -135,7 +134,7 @@ protected function getExpandsMappings():array
135134
/**
136135
* @return array
137136
*/
138-
protected function getAllowedRelations():array
137+
public function getAllowedRelations():array
139138
{
140139
try {
141140
$relations = [];
@@ -169,6 +168,11 @@ protected function getAllowedRelations():array
169168
}
170169
}
171170

171+
static public function getFirstLevelAllowedFields(array $relations):array{
172+
return array_filter($relations, function($elem) {
173+
return !str_contains(trim($elem), ".");
174+
});
175+
}
172176
/**
173177
* @return array
174178
*/
@@ -415,7 +419,7 @@ protected function _expand(array $values, ?string $expand, array $fields = [], a
415419
* @param string $prefix
416420
* @return string
417421
*/
418-
public static function filterExpandByPrefix(?string $expand_str, string $prefix):?string
422+
public static function filterExpandByPrefix(?string $expand_str, string $prefix, string $default = ''):?string
419423
{
420424
if(empty($expand_str)) return '';
421425
$expand_to = explode(',', $expand_str);
@@ -428,6 +432,10 @@ public static function filterExpandByPrefix(?string $expand_str, string $prefix)
428432
if (strlen($res) > 0) $res .= ',';
429433
$res .= str_replace_first($prefix . ".", "", strtolower(trim($filtered_expand_elem)));
430434
}
435+
if(!empty($default)){
436+
if(strlen($res) > 0) $res .= ',';
437+
$res .= $default;
438+
}
431439
return $res;
432440
}
433441

Libs/ModelSerializers/IModelSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ interface IModelSerializer
2222
* @return array
2323
* @throw HTTP403ForbiddenException
2424
*/
25-
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array() );
25+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = []);
2626
}

app/Http/Controllers/Apis/Protected/Main/OAuth2TeamsApiController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ public function getMyTeam($team_id){
148148
->getSerializer($team)
149149
->serialize
150150
(
151-
$expand = Request::input('expand',''),
152-
$fields = [],
151+
$expand = Request::input('expand', ''),
152+
$fields = [],
153153
$relations = [],
154-
$params = [
154+
$params = [
155155
'current_member' => $current_member
156156
]
157157
)

app/Http/Controllers/Apis/Protected/Summit/OAuth2PresentationCategoryGroupController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ public function getTrackGroupBySummit($summit_id, $track_group_id){
300300
if(is_null($track_group))
301301
return $this->error404();
302302

303-
return $this->ok(SerializerRegistry::getInstance()->getSerializer($track_group)->serialize( Request::input('expand', '')));
303+
return $this->ok(SerializerRegistry::getInstance()->getSerializer($track_group)->serialize(Request::input('expand', '')));
304304
} catch (ValidationException $ex1) {
305305
Log::warning($ex1);
306306
return $this->error412([$ex1->getMessage()]);

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ public function getAllSummitByIdOrSlugRegistrationStats($id)
448448
SerializerUtils::getExpand(),
449449
SerializerUtils::getFields(),
450450
SerializerUtils::getRelations(),
451-
[ 'filter' => $filter ]
451+
['filter' => $filter]
452452
)
453453
);
454454
});

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitNotificationsApiController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ public function approveNotification($summit_id, $notification_id){
334334
if (is_null($summit)) return $this->error404();
335335

336336
$notification = $this->push_notification_service->approveNotification($summit, $this->resource_server_context->getCurrentUser(), $notification_id);
337-
return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize( Request::input('expand', '')));
337+
return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize(Request::input('expand', '')));
338338
} catch (ValidationException $ex1) {
339339
Log::warning($ex1);
340340
return $this->error412(array($ex1->getMessage()));
@@ -358,7 +358,7 @@ public function unApproveNotification($summit_id, $notification_id){
358358
if (is_null($summit)) return $this->error404();
359359

360360
$notification = $this->push_notification_service->unApproveNotification($summit, $this->resource_server_context->getCurrentUser(), $notification_id);
361-
return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize( Request::input('expand', '')));
361+
return $this->updated(SerializerRegistry::getInstance()->getSerializer($notification)->serialize(Request::input('expand', '')));
362362
} catch (ValidationException $ex1) {
363363
Log::warning($ex1);
364364
return $this->error412(array($ex1->getMessage()));

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitRSVPTemplatesApiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ public function getRSVPTemplate($summit_id, $template_id){
196196
return $this->error404();
197197
}
198198

199-
return $this->ok(SerializerRegistry::getInstance()->getSerializer($template)->serialize($expand,[], $relations));
199+
return $this->ok(SerializerRegistry::getInstance()->getSerializer($template)->serialize($expand, [], $relations));
200200
}
201201
catch (ValidationException $ex1) {
202202
Log::warning($ex1);

app/Http/Controllers/Apis/Protected/Summit/OAuth2SummitSpeakersApiController.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,9 +1037,9 @@ public function updateSpeaker($speaker_id)
10371037

10381038
return $this->updated(SerializerRegistry::getInstance()
10391039
->getSerializer($speaker, SerializerRegistry::SerializerType_Private)->serialize(
1040-
SerializerUtils::getExpand(),
1041-
SerializerUtils::getFields(),
1042-
SerializerUtils::getRelations()
1040+
SerializerUtils::getExpand(),
1041+
SerializerUtils::getFields(),
1042+
SerializerUtils::getRelations()
10431043
));
10441044
});
10451045
}

app/ModelSerializers/AbstractMemberSerializer.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,10 @@ class AbstractMemberSerializer extends SilverStripeSerializer
5858
* @param array $params
5959
* @return array
6060
*/
61-
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
61+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
6262
{
6363
$member = $this->object;
6464
if(!$member instanceof Member) return [];
65-
66-
if(!count($relations)) $relations = $this->getAllowedRelations();
67-
6865
$values = parent::serialize($expand, $fields, $relations, $params);
6966

7067
if(in_array('groups', $relations) && !isset($values['groups']))

app/ModelSerializers/AffiliationSerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class AffiliationSerializer extends SilverStripeSerializer
3030
'OrganizationId' => 'organization_id:json_int'
3131
];
3232

33-
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
33+
public function serialize($expand = null, array $fields = [], array $relations = [], array $params = [])
3434
{
3535
$affiliation = $this->object;
3636
if (!$affiliation instanceof Affiliation) return [];

0 commit comments

Comments
 (0)