-
-
Notifications
You must be signed in to change notification settings - Fork 126
Expand file tree
/
Copy pathSCIMRepresentationModel.cs
More file actions
65 lines (57 loc) · 2.8 KB
/
SCIMRepresentationModel.cs
File metadata and controls
65 lines (57 loc) · 2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// Copyright (c) SimpleIdServer. All rights reserved.
// Licensed under the Apache License, Version 2.0. See LICENSE in the project root for license information.
using MongoDB.Driver;
using SimpleIdServer.Scim.Domains;
using SimpleIdServer.Scim.Persistence.MongoDB.Extensions;
using SimpleIdServer.Scim.Persistence.MongoDB.Infrastructures;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
namespace SimpleIdServer.Scim.Persistence.MongoDB.Models
{
public class SCIMRepresentationModel : SCIMRepresentation
{
public SCIMRepresentationModel() : base()
{
SchemaRefs = new List<CustomMongoDBRef>();
}
public SCIMRepresentationModel(SCIMRepresentation representation, string schemaCollectionName) : this()
{
Id = representation.Id;
RealmName = representation.RealmName;
ExternalId = representation.ExternalId;
ResourceType = representation.ResourceType;
Version = representation.Version;
Created = representation.Created;
LastModified = representation.LastModified;
DisplayName = representation.DisplayName;
SchemaRefs = representation.Schemas.Select(s => new CustomMongoDBRef(schemaCollectionName, s.Id)).ToList();
}
public ICollection<CustomMongoDBRef> SchemaRefs { get; set; }
public ICollection<CustomMongoDBRef> AttributeRefs { get; set; }
public async Task IncludeAll(SCIMDbContext dbContext, CancellationToken cancellationToken = default)
{
IncludeSchemas(dbContext.Database);
await IncludeAttributes(dbContext, cancellationToken);
}
public void IncludeSchemas(IMongoDatabase database)
{
Schemas = MongoDBEntity.GetReferences<SCIMSchema>(SchemaRefs, database);
}
public async Task IncludeAttributes(SCIMDbContext dbContext, CancellationToken cancellationToken = default)
{
// Optimize MongoDB query for large result sets by using Find with explicit options
// This provides better performance than LINQ for representations with many attributes (e.g., a group with 20k+ member attributes)
var filter = Builders<SCIMRepresentationAttribute>.Filter.Eq(a => a.RepresentationId, Id);
var findOptions = new FindOptions<SCIMRepresentationAttribute>
{
// Use configured batch size to reduce round trips to MongoDB
BatchSize = dbContext.Options.BatchSize
};
using var cursor = await dbContext.SCIMRepresentationAttributeLst
.FindAsync(filter, findOptions, cancellationToken);
FlatAttributes = await cursor.ToListAsync(cancellationToken);
}
}
}