Skip to content

Commit

Permalink
Improve meeting mediafile can_access check performance (#4347)
Browse files Browse the repository at this point in the history
  • Loading branch information
bastianjoel authored and openslides-automation committed Nov 13, 2024
1 parent 2a25888 commit c36e46c
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { Fieldsets } from 'src/app/site/services/model-request-builder';
import { TypedFieldset } from '../../../site/services/model-request-builder/model-request-builder.service';
import { BaseRepository } from '../base-repository';
import { MeetingMediafileRepositoryService } from '../meeting-mediafile/meeting-mediafile-repository.service';
import { ProjectionRepositoryService } from '../projections/projection-repository.service';
import { RepositoryServiceCollectorService } from '../repository-service-collector.service';
import { MediafileAction } from './mediafile.action';

Expand All @@ -26,7 +25,6 @@ export class MediafileRepositoryService extends BaseRepository<ViewMediafile, Me
public constructor(
repositoryServiceCollector: RepositoryServiceCollectorService,
private activeMeetingService: ActiveMeetingService,
private projectionRepo: ProjectionRepositoryService,
private meetingMediaRepo: MeetingMediafileRepositoryService
) {
super(repositoryServiceCollector, Mediafile);
Expand Down Expand Up @@ -146,8 +144,6 @@ export class MediafileRepositoryService extends BaseRepository<ViewMediafile, Me
const viewModel = super.createViewModel(model);
viewModel.getEnsuredActiveMeetingId = (): number => this.activeMeetingId;
viewModel.getEnsuredActiveMeeting = (): ViewMeeting => this.activeMeetingService.meeting;
viewModel.getProjectedContentObjects = (): string[] =>
this.projectionRepo.getViewModelList().map(p => p.content_object_id);
viewModel.getMeetingMediafile = (): ViewMeetingMediafile => this.getMeetingMediafile(model);
return viewModel;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { ViewMeetingMediafile } from 'src/app/site/pages/meetings/pages/mediafil

import { ActiveMeetingIdService } from '../../../site/pages/meetings/services/active-meeting-id.service';
import { BaseRepository } from '../base-repository';
import { ProjectionRepositoryService } from '../projections/projection-repository.service';
import { RepositoryServiceCollectorService } from '../repository-service-collector.service';

@Injectable({
Expand All @@ -16,8 +15,7 @@ export class MeetingMediafileRepositoryService extends BaseRepository<ViewMeetin

public constructor(
repositoryServiceCollector: RepositoryServiceCollectorService,
private activeMeetingIdService: ActiveMeetingIdService,
private projectionRepo: ProjectionRepositoryService
private activeMeetingIdService: ActiveMeetingIdService
) {
super(repositoryServiceCollector, MeetingMediafile);

Expand Down Expand Up @@ -66,8 +64,6 @@ export class MeetingMediafileRepositoryService extends BaseRepository<ViewMeetin
protected override createViewModel(model: MeetingMediafile): ViewMeetingMediafile {
const viewModel = super.createViewModel(model);
viewModel.getEnsuredActiveMeetingId = (): number => this.activeMeetingIdService.meetingId;
viewModel.getProjectedContentObjects = (): string[] =>
this.projectionRepo.getViewModelList().map(p => p.content_object_id);
return viewModel;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fqid, Id } from 'src/app/domain/definitions/key-types';
import { Id } from 'src/app/domain/definitions/key-types';
import { HasProperties } from 'src/app/domain/interfaces/has-properties';
import { ViewMediafileMeetingUsageKey } from 'src/app/domain/models/mediafiles/mediafile.constants';
import { Meeting } from 'src/app/domain/models/meetings/meeting';
Expand Down Expand Up @@ -74,7 +74,6 @@ export class ViewMediafile extends BaseProjectableViewModel<Mediafile> {
*/
public getEnsuredActiveMeetingId!: () => Id;
public getEnsuredActiveMeeting!: () => ViewMeeting;
public getProjectedContentObjects!: () => Fqid[];
public getMeetingMediafile!: (meetingId?: Id) => ViewMeetingMediafile;

public override canAccess(): boolean {
Expand All @@ -87,11 +86,7 @@ export class ViewMediafile extends BaseProjectableViewModel<Mediafile> {
}

return !this.getEnsuredActiveMeetingId();
} else if (
this.meeting_mediafiles.some(
mm => this.getProjectedContentObjects().indexOf(`meeting_mediafile/${mm.id}`) !== -1
)
) {
} else if (this.meeting_mediafiles.some(mm => !!mm.projection_ids?.length)) {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Fqid, Id } from 'src/app/domain/definitions/key-types';
import { Id } from 'src/app/domain/definitions/key-types';
import { HasProperties } from 'src/app/domain/interfaces/has-properties';
import { ViewMediafileMeetingUsageKey } from 'src/app/domain/models/mediafiles/mediafile.constants';
import { PROJECTIONDEFAULT, ProjectiondefaultValue } from 'src/app/domain/models/projector/projection-default';
Expand Down Expand Up @@ -42,7 +42,6 @@ export class ViewMeetingMediafile extends BaseProjectableViewModel<MeetingMediaf
* @returns The id of the currently active meeting
*/
public getEnsuredActiveMeetingId!: () => Id;
public getProjectedContentObjects!: () => Fqid[];

public override canAccess(): boolean {
return this.getEnsuredActiveMeetingId() === this.meeting_id || !this.getEnsuredActiveMeetingId();
Expand Down

0 comments on commit c36e46c

Please sign in to comment.