Skip to content

Commit 1a06980

Browse files
committed
Fix query performance by reordering property names
1 parent fd1103b commit 1a06980

File tree

3 files changed

+42
-42
lines changed

3 files changed

+42
-42
lines changed

src/blob/persistence/LokiBlobMetadataStore.ts

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -383,8 +383,8 @@ export default class LokiBlobMetadataStore
383383
): Promise<ContainerModel> {
384384
const coll = this.db.getCollection(this.CONTAINERS_COLLECTION);
385385
const doc = coll.findOne({
386-
accountName: container.accountName,
387-
name: container.name
386+
name: container.name,
387+
accountName: container.accountName
388388
});
389389

390390
if (doc) {
@@ -817,7 +817,7 @@ export default class LokiBlobMetadataStore
817817
container: string
818818
): Promise<void> {
819819
const coll = this.db.getCollection(this.CONTAINERS_COLLECTION);
820-
const doc = coll.findOne({ accountName: account, name: container });
820+
const doc = coll.findOne({ name: container, accountName: account });
821821
if (!doc) {
822822
const requestId = context ? context.contextId : undefined;
823823
throw StorageErrorFactory.getContainerNotFound(requestId);
@@ -1032,9 +1032,9 @@ export default class LokiBlobMetadataStore
10321032
);
10331033
const coll = this.db.getCollection(this.BLOBS_COLLECTION);
10341034
const blobDoc = coll.findOne({
1035+
name: blob.name,
10351036
accountName: blob.accountName,
10361037
containerName: blob.containerName,
1037-
name: blob.name,
10381038
snapshot: blob.snapshot
10391039
});
10401040

@@ -1219,9 +1219,9 @@ export default class LokiBlobMetadataStore
12191219
): Promise<BlobModel | undefined> {
12201220
const coll = this.db.getCollection(this.BLOBS_COLLECTION);
12211221
const blobDoc = coll.findOne({
1222+
name: blob,
12221223
accountName: account,
12231224
containerName: container,
1224-
name: blob,
12251225
snapshot
12261226
});
12271227

@@ -1799,9 +1799,9 @@ export default class LokiBlobMetadataStore
17991799

18001800
const coll = this.db.getCollection(this.BLOBS_COLLECTION);
18011801
const doc = coll.findOne({
1802+
name: blob,
18021803
accountName: account,
18031804
containerName: container,
1804-
name: blob,
18051805
snapshot
18061806
});
18071807

@@ -1833,9 +1833,9 @@ export default class LokiBlobMetadataStore
18331833
> {
18341834
const coll = this.db.getCollection(this.BLOBS_COLLECTION);
18351835
const doc = coll.findOne({
1836+
name: blob,
18361837
accountName: account,
18371838
containerName: container,
1838-
name: blob,
18391839
snapshot
18401840
});
18411841
if (!doc) {
@@ -2323,9 +2323,9 @@ export default class LokiBlobMetadataStore
23232323

23242324
const blobColl = this.db.getCollection(this.BLOBS_COLLECTION);
23252325
const blobDoc = blobColl.findOne({
2326+
name: block.blobName,
23262327
accountName: block.accountName,
2327-
containerName: block.containerName,
2328-
name: block.blobName
2328+
containerName: block.containerName
23292329
});
23302330

23312331
let blobExist = false;
@@ -2364,9 +2364,9 @@ export default class LokiBlobMetadataStore
23642364
// If the new block ID does not have same length with before uncommitted block ID, return failure.
23652365
if (blobExist) {
23662366
const existBlockDoc = coll.findOne({
2367+
blobName: block.blobName,
23672368
accountName: block.accountName,
23682369
containerName: block.containerName,
2369-
blobName: block.blobName
23702370
});
23712371
if (existBlockDoc) {
23722372
if (
@@ -2379,10 +2379,10 @@ export default class LokiBlobMetadataStore
23792379
}
23802380

23812381
const blockDoc = coll.findOne({
2382+
name: block.name,
23822383
accountName: block.accountName,
23832384
containerName: block.containerName,
23842385
blobName: block.blobName,
2385-
name: block.name,
23862386
isCommitted: block.isCommitted
23872387
});
23882388

@@ -3207,7 +3207,7 @@ export default class LokiBlobMetadataStore
32073207
forceExist?: boolean
32083208
): Promise<ContainerModel | undefined> {
32093209
const coll = this.db.getCollection(this.CONTAINERS_COLLECTION);
3210-
const doc = coll.findOne({ accountName: account, name: container });
3210+
const doc = coll.findOne({ name: container, accountName: account });
32113211

32123212
if (forceExist === undefined || forceExist === true) {
32133213
if (!doc) {
@@ -3271,7 +3271,7 @@ export default class LokiBlobMetadataStore
32713271
forceExist?: boolean
32723272
): Promise<ContainerModel | undefined> {
32733273
const coll = this.db.getCollection(this.CONTAINERS_COLLECTION);
3274-
const doc = coll.findOne({ accountName: account, name: container });
3274+
const doc = coll.findOne({ name: container, accountName: account });
32753275

32763276
if (!doc) {
32773277
if (forceExist) {
@@ -3347,9 +3347,9 @@ export default class LokiBlobMetadataStore
33473347

33483348
const coll = this.db.getCollection(this.BLOBS_COLLECTION);
33493349
const doc = coll.findOne({
3350+
name: blob,
33503351
accountName: account,
33513352
containerName: container,
3352-
name: blob,
33533353
snapshot
33543354
});
33553355

src/queue/persistence/LokiQueueMetadataStore.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -236,10 +236,10 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
236236
prefix === ""
237237
? { $loki: { $gt: marker }, accountName: account }
238238
: {
239-
name: { $regex: `^${this.escapeRegex(prefix)}` },
240-
$loki: { $gt: marker },
241-
accountName: account
242-
};
239+
name: { $regex: `^${this.escapeRegex(prefix)}` },
240+
$loki: { $gt: marker },
241+
accountName: account
242+
};
243243

244244
// Get one more item to help check if the query reach the tail of the collection.
245245
const docs = coll
@@ -283,7 +283,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
283283
context?: Context
284284
): Promise<QueueModel> {
285285
const coll = this.db.getCollection(this.QUEUES_COLLECTION);
286-
const doc = coll.findOne({ accountName: account, name: queue });
286+
const doc = coll.findOne({ name: queue, accountName: account });
287287
if (!doc) {
288288
const requestId = context ? context.contextID : undefined;
289289
throw StorageErrorFactory.getQueueNotFound(requestId);
@@ -307,8 +307,8 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
307307
): Promise<QUEUE_STATUSCODE> {
308308
const coll = this.db.getCollection(this.QUEUES_COLLECTION);
309309
const doc = coll.findOne({
310-
accountName: queue.accountName,
311-
name: queue.name
310+
name: queue.name,
311+
accountName: queue.accountName
312312
});
313313

314314
// Check whether a conflict exists if there exist a queue with the given name.
@@ -386,7 +386,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
386386
context?: Context
387387
): Promise<void> {
388388
const coll = this.db.getCollection(this.QUEUES_COLLECTION);
389-
const doc = coll.findOne({ accountName: account, name: queue });
389+
const doc = coll.findOne({ name: queue, accountName: account });
390390

391391
if (!doc) {
392392
const requestId = context ? context.contextID : undefined;
@@ -418,7 +418,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
418418
context?: Context
419419
): Promise<void> {
420420
const coll = this.db.getCollection(this.QUEUES_COLLECTION);
421-
const doc = coll.findOne({ accountName: account, name: queue });
421+
const doc = coll.findOne({ name: queue, accountName: account });
422422

423423
if (!doc) {
424424
const requestId = context ? context.contextID : undefined;
@@ -446,7 +446,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
446446
context?: Context
447447
): Promise<void> {
448448
const coll = this.db.getCollection(this.QUEUES_COLLECTION);
449-
const doc = coll.findOne({ accountName: account, name: queue });
449+
const doc = coll.findOne({ name: queue, accountName: account });
450450

451451
if (!doc) {
452452
const requestId = context ? context.contextID : undefined;
@@ -472,7 +472,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
472472
context?: Context
473473
): Promise<number> {
474474
const queueColl = this.db.getCollection(this.QUEUES_COLLECTION);
475-
const doc = queueColl.findOne({ accountName: account, name: queue });
475+
const doc = queueColl.findOne({ name: queue, accountName: account });
476476
if (!doc) {
477477
const requestId = context ? context.contextID : undefined;
478478
throw StorageErrorFactory.getQueueNotFound(requestId);
@@ -649,9 +649,9 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
649649

650650
const coll = this.db.getCollection(this.MESSAGES_COLLECTION);
651651
const doc = coll.findOne({
652+
messageId,
652653
accountName: account,
653-
queueName: queue,
654-
messageId
654+
queueName: queue
655655
});
656656

657657
if (!doc) {
@@ -687,9 +687,9 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
687687

688688
const coll = this.db.getCollection(this.MESSAGES_COLLECTION);
689689
const doc = coll.findOne({
690+
messageId: message.messageId,
690691
accountName: message.accountName,
691-
queueName: message.queueName,
692-
messageId: message.messageId
692+
queueName: message.queueName
693693
});
694694

695695
if (!doc) {
@@ -783,7 +783,7 @@ export default class LokiQueueMetadataStore implements IQueueMetadataStore {
783783
context?: Context
784784
): void {
785785
const queueColl = this.db.getCollection(this.QUEUES_COLLECTION);
786-
const queueDoc = queueColl.findOne({ accountName: account, name: queue });
786+
const queueDoc = queueColl.findOne({ name: queue, accountName: account });
787787
if (!queueDoc) {
788788
const requestId = context ? context.contextID : undefined;
789789
throw StorageErrorFactory.getQueueNotFound(requestId);

src/table/persistence/LokiTableMetadataStore.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
265265
);
266266

267267
const doc = tableEntityCollection.findOne({
268-
PartitionKey: entity.PartitionKey,
269-
RowKey: entity.RowKey
268+
RowKey: entity.RowKey,
269+
PartitionKey: entity.PartitionKey
270270
});
271271
if (doc) {
272272
throw StorageErrorFactory.getEntityAlreadyExist(context);
@@ -392,8 +392,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
392392

393393
if (partitionKey !== undefined && rowKey !== undefined) {
394394
const doc = tableEntityCollection.findOne({
395-
PartitionKey: partitionKey,
396-
RowKey: rowKey
395+
RowKey: rowKey,
396+
PartitionKey: partitionKey
397397
}) as Entity;
398398

399399
this.checkForMissingEntity(doc, context);
@@ -503,8 +503,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
503503
): Promise<Entity | undefined> {
504504
const entityCollection = this.getEntityCollection(account, table, context);
505505
const requestedDoc = entityCollection.findOne({
506-
PartitionKey: partitionKey,
507-
RowKey: rowKey
506+
RowKey: rowKey,
507+
PartitionKey: partitionKey
508508
}) as Entity;
509509

510510
return requestedDoc;
@@ -919,8 +919,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
919919
);
920920

921921
const doc = tableEntityCollection.findOne({
922-
PartitionKey: entity.PartitionKey,
923-
RowKey: entity.RowKey
922+
RowKey: entity.RowKey,
923+
PartitionKey: entity.PartitionKey
924924
}) as Entity;
925925

926926
if (!doc) {
@@ -968,8 +968,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
968968
);
969969

970970
const doc = tableEntityCollection.findOne({
971-
PartitionKey: entity.PartitionKey,
972-
RowKey: entity.RowKey
971+
RowKey: entity.RowKey,
972+
PartitionKey: entity.PartitionKey
973973
}) as Entity;
974974

975975
if (!doc) {
@@ -1062,8 +1062,8 @@ export default class LokiTableMetadataStore implements ITableMetadataStore {
10621062
};
10631063
// lokijs applies this insert as an upsert
10641064
const doc = tableBatchCollection.findOne({
1065-
PartitionKey: entity.PartitionKey,
1066-
RowKey: entity.RowKey
1065+
RowKey: entity.RowKey,
1066+
PartitionKey: entity.PartitionKey
10671067
});
10681068
// we can't rely on upsert behavior if documents already exist
10691069
if (doc) {

0 commit comments

Comments
 (0)