Skip to content

Commit

Permalink
fix: collation (#251)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbystedt authored Aug 28, 2024
1 parent 684710e commit 5fff395
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 73 deletions.
1 change: 1 addition & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const HEADER_VAULT_ROLE_ID = 'x-vault-role-id';
export const HEADER_BROKER_TOKEN = 'x-broker-token';

export const COLLECTION_MAX_EMBEDDED = 40;
export const COLLECTION_COLLATION_LOCALE = 'en';

export const INTENTION_DEFAULT_TTL_SECONDS = 600;
export const INTENTION_MIN_TTL_SECONDS = 30;
Expand Down
154 changes: 81 additions & 73 deletions src/persistence/mongo/collection-mongo.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { CollectionDtoUnion } from '../dto/collection-dto-union.type';
import { CollectionConfigDto } from '../dto/collection-config.dto';
import { getRepositoryFromCollectionName } from './mongo.util';
import { CollectionSearchResult } from '../../collection/dto/collection-search-result.dto';
import { COLLECTION_COLLATION_LOCALE } from '../../constants';

@Injectable()
export class CollectionMongoRepository implements CollectionRepository {
Expand Down Expand Up @@ -171,88 +172,95 @@ export class CollectionMongoRepository implements CollectionRepository {
]
: [];
return repo
.aggregate([
...idQuery,
...vertexQuery,
{
$replaceRoot: { newRoot: { ['collection']: `$$ROOT` } },
},
...tagsQuery,
...upstreamQuery,
// upstream
{
$lookup: {
from: 'edge',
localField: 'collection.vertex',
foreignField: 'target',
pipeline: [
{
$lookup: {
from: 'vertex',
localField: 'source',
foreignField: '_id',
as: 'vertex',
.aggregate(
[
...idQuery,
...vertexQuery,
{
$replaceRoot: { newRoot: { ['collection']: `$$ROOT` } },
},
...tagsQuery,
...upstreamQuery,
// upstream
{
$lookup: {
from: 'edge',
localField: 'collection.vertex',
foreignField: 'target',
pipeline: [
{
$lookup: {
from: 'vertex',
localField: 'source',
foreignField: '_id',
as: 'vertex',
},
},
},
{ $unwind: '$vertex' },
],
as: 'upstream',
{ $unwind: '$vertex' },
],
as: 'upstream',
},
},
},
// downstream
{
$lookup: {
from: 'edge',
localField: 'collection.vertex',
foreignField: 'source',
pipeline: [
{
$lookup: {
from: 'vertex',
localField: 'target',
foreignField: '_id',
as: 'vertex',
// downstream
{
$lookup: {
from: 'edge',
localField: 'collection.vertex',
foreignField: 'source',
pipeline: [
{
$lookup: {
from: 'vertex',
localField: 'target',
foreignField: '_id',
as: 'vertex',
},
},
},
{ $unwind: '$vertex' },
],
as: 'downstream',
{ $unwind: '$vertex' },
],
as: 'downstream',
},
},
},
...downstreamQuery,
{
$lookup: {
from: 'vertex',
localField: 'collection.vertex',
foreignField: '_id',
as: 'vertex',
...downstreamQuery,
{
$lookup: {
from: 'vertex',
localField: 'collection.vertex',
foreignField: '_id',
as: 'vertex',
},
},
},
{ $unwind: '$vertex' },
{
$addFields: {
id: '$_id',
{ $unwind: '$vertex' },
{
$addFields: {
id: '$_id',
},
},
},
{
$unset: ['_id'],
},
{
$facet: {
data: [
{
$sort: {
[`collection.${sortField}`]: sortDir,
{
$unset: ['_id'],
},
{
$facet: {
data: [
{
$sort: {
[`collection.${sortField}`]: sortDir,
},
},
},
{ $skip: offset },
{ $limit: limit },
],
meta: [{ $count: 'total' }],
{ $skip: offset },
{ $limit: limit },
],
meta: [{ $count: 'total' }],
},
},
{ $unwind: '$meta' },
],
{
collation: {
locale: COLLECTION_COLLATION_LOCALE,
},
},
{ $unwind: '$meta' },
])
)
.toArray()
.then((array) => {
if (array[0]) {
Expand Down

0 comments on commit 5fff395

Please sign in to comment.