Skip to content

Commit

Permalink
Merge pull request #5589 from christianbeeznest/ofaj-21784
Browse files Browse the repository at this point in the history
Internal: Improve loading time in courseHome page - refs BT#21784
  • Loading branch information
christianbeeznest authored Jun 21, 2024
2 parents 52fc9ab + 1da244f commit c6545bd
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 13 deletions.
11 changes: 9 additions & 2 deletions assets/vue/services/sessionService.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@ async function findUserSubscriptions(userIri, listType) {
export default {
/**
* @param {string} iri
* @param useBasic
* @returns {Promise<Object>}
*/
async find(iri) {
const { data } = await api.get(iri)
async find(iri, useBasic = false) {
const endpoint = iri
const groups = useBasic ? ['session:basic'] : ['session:read']
const { data } = await api.get(endpoint, {
params: {
'groups[]': groups
}
})

return data
},
Expand Down
8 changes: 4 additions & 4 deletions assets/vue/store/cidReq.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,21 @@ export const useCidReqStore = defineStore("cidReq", () => {
}
}

const setSessionByIri = async (sId) => {
const setSessionByIri = async (sId, useBasic = true) => {
const sessionIri = `/api/sessions/${sId}`

if (session.value && sessionIri === session.value["@id"]) {
return
}

try {
session.value = await sessionService.find(sessionIri)
session.value = await sessionService.find(sessionIri, useBasic)
} catch (error) {
console.error(error)
}
}

const setCourseAndSessionById = (cId, sId = undefined) => {
const setCourseAndSessionById = (cId, sId = undefined, useBasic = true) => {
if (!cId) {
return Promise.resolve()
}
Expand All @@ -103,7 +103,7 @@ export const useCidReqStore = defineStore("cidReq", () => {
return coursePromise
}

const sessionPromise = setSessionByIri(sId)
const sessionPromise = setSessionByIri(sId, useBasic)

return Promise.all([coursePromise, sessionPromise])
}
Expand Down
23 changes: 16 additions & 7 deletions src/CoreBundle/Entity/Session.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

namespace Chamilo\CoreBundle\Entity;

use ApiPlatform\Core\Serializer\Filter\GroupFilter;
use ApiPlatform\Doctrine\Orm\Filter\OrderFilter;
use ApiPlatform\Doctrine\Orm\Filter\SearchFilter;
use ApiPlatform\Metadata\ApiFilter;
Expand Down Expand Up @@ -35,8 +36,9 @@
#[ApiResource(
operations: [
new Get(
uriTemplate: '/sessions/{id}',
normalizationContext: [
'groups' => ['session:read', 'session:item:read'],
'groups' => ['session:basic'],
],
security: "is_granted('ROLE_ADMIN') or is_granted('VIEW', object)"
),
Expand Down Expand Up @@ -96,7 +98,7 @@
new Post(security: "is_granted('ROLE_ADMIN')"),
new Delete(security: "is_granted('DELETE', object)"),
],
normalizationContext: ['groups' => ['session:read']],
normalizationContext: ['groups' => ['session:basic']],
denormalizationContext: ['groups' => ['session:write']],
security: "is_granted('ROLE_ADMIN')"
)]
Expand All @@ -105,9 +107,10 @@
#[ORM\EntityListeners([SessionListener::class])]
#[ORM\Entity(repositoryClass: SessionRepository::class)]
#[UniqueEntity('title')]
#[ApiFilter(filterClass: SearchFilter::class, properties: ['title' => 'partial'])]
#[ApiFilter(filterClass: PropertyFilter::class)]
#[ApiFilter(filterClass: OrderFilter::class, properties: ['id', 'title'])]
#[ApiFilter(SearchFilter::class, properties: ['title' => 'partial'])]
#[ApiFilter(PropertyFilter::class)]
#[ApiFilter(OrderFilter::class, properties: ['id', 'title'])]
#[ApiFilter(GroupFilter::class, arguments: ['parameterName' => 'groups'])]
class Session implements ResourceWithAccessUrlInterface, Stringable
{
public const READ_ONLY = 1;
Expand All @@ -123,6 +126,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
public const SESSION_ADMIN = 4;

#[Groups([
'session:basic',
'session:read',
'session_rel_user:read',
'session_rel_course_rel_user:read',
Expand All @@ -149,6 +153,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
mappedBy: 'session',
targetEntity: SessionRelCourse::class,
cascade: ['persist'],
fetch: 'EXTRA_LAZY',
orphanRemoval: true
)]
protected Collection $courses;
Expand All @@ -163,6 +168,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
mappedBy: 'session',
targetEntity: SessionRelUser::class,
cascade: ['persist', 'remove'],
fetch: 'EXTRA_LAZY',
orphanRemoval: true
)]
protected Collection $users;
Expand Down Expand Up @@ -221,6 +227,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable

#[Assert\NotBlank]
#[Groups([
'session:basic',
'session:read',
'session:write',
'session_rel_course_rel_user:read',
Expand All @@ -235,6 +242,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
protected string $title;

#[Groups([
'session:basic',
'session:read',
'session:write',
])]
Expand All @@ -252,11 +260,11 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
#[ORM\Column(name: 'duration', type: 'integer', nullable: true)]
protected ?int $duration = null;

#[Groups(['session:read'])]
#[Groups(['session:basic', 'session:read'])]
#[ORM\Column(name: 'nbr_courses', type: 'integer', unique: false, nullable: false)]
protected int $nbrCourses;

#[Groups(['session:read'])]
#[Groups(['session:basic', 'session:read'])]
#[ORM\Column(name: 'nbr_users', type: 'integer', unique: false, nullable: false)]
protected int $nbrUsers;

Expand All @@ -265,6 +273,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
protected int $nbrClasses;

#[Groups([
'session:basic',
'session:read',
'session:write',
])]
Expand Down

0 comments on commit c6545bd

Please sign in to comment.