Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal: Improve loading time in courseHome page - refs BT#21784 #5589

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
}
Comment on lines +23 to +25
Copy link
Member

@AngelFQC AngelFQC Jun 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

El GroupFilter no está configurado en la clase Session. Entonces, no sería necesario pasarlo en params ya que estás poniendo el grupo en otro endpoint.

Aunque usar GroupFilter en Session sería una opción para no tener otro endpoint

})

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 @@ -34,8 +35,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 @@ -95,7 +97,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 @@ -104,9 +106,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 @@ -121,6 +124,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 @@ -147,6 +151,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable
mappedBy: 'session',
targetEntity: SessionRelCourse::class,
cascade: ['persist'],
fetch: 'EXTRA_LAZY',
orphanRemoval: true
)]
protected Collection $courses;
Expand All @@ -161,6 +166,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 @@ -219,6 +225,7 @@ class Session implements ResourceWithAccessUrlInterface, Stringable

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

#[Groups([
'session:basic',
'session:read',
'session:write',
])]
Expand All @@ -250,11 +258,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'])]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.

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

#[Groups(['session:read'])]
#[Groups(['session:basic', 'session:read'])]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perl-style comments are not allowed. Use "// Comment." or "/* comment */" instead.

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

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

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