From e614471a63cff68fbb810e4a18eb8178c3160960 Mon Sep 17 00:00:00 2001 From: Jonas Gottschau Date: Sun, 12 Nov 2023 20:57:35 +0100 Subject: [PATCH] add index (#373) update version --- ChangeLog.md | 3 +++ .../Hangfire.Mongo.Sample.ASPNetCore.csproj | 2 +- .../Hangfire.Mongo.Sample.CosmosDB.csproj | 2 +- .../Hangfire.Mongo.Sample.NETCore.csproj | 2 +- .../Migration/Hangfire-Mongo-Schema-021.zip | Bin 0 -> 2953 bytes .../Migration/Mongo/MongoDatabaseFiller.cs | 4 ++- .../Migration/Version20MigrationStepFacts.cs | 2 -- src/Hangfire.Mongo/Hangfire.Mongo.csproj | 4 +-- .../Migration/MongoSchemaExtensions.cs | 25 +----------------- .../Steps/Version22/00_AddQueueIndex.cs | 21 +++++++++++++++ src/Hangfire.Mongo/MongoSchema.cs | 7 ++++- 11 files changed, 39 insertions(+), 33 deletions(-) create mode 100644 src/Hangfire.Mongo.Tests/Migration/Hangfire-Mongo-Schema-021.zip create mode 100644 src/Hangfire.Mongo/Migration/Steps/Version22/00_AddQueueIndex.cs diff --git a/ChangeLog.md b/ChangeLog.md index ba8357b..2693ccd 100644 --- a/ChangeLog.md +++ b/ChangeLog.md @@ -1,6 +1,9 @@ ## Change log +### v1.9.14 +- Add index needed for improved performance of MongoMonitoringApi.GetQueues + ### v1.9.13 - Improve performance of MongoMonitoringApi.GetQueues() diff --git a/src/Hangfire.Mongo.Sample.ASPNetCore/Hangfire.Mongo.Sample.ASPNetCore.csproj b/src/Hangfire.Mongo.Sample.ASPNetCore/Hangfire.Mongo.Sample.ASPNetCore.csproj index e861464..ac3270f 100644 --- a/src/Hangfire.Mongo.Sample.ASPNetCore/Hangfire.Mongo.Sample.ASPNetCore.csproj +++ b/src/Hangfire.Mongo.Sample.ASPNetCore/Hangfire.Mongo.Sample.ASPNetCore.csproj @@ -2,7 +2,7 @@ net6.0 - 1.9.13 + 1.9.14 MongoDB storage implementation for Hangfire (background job system for ASP.NET applications). Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau Sergey Zwezdin, Martin Lobger, Jonas Gottschau diff --git a/src/Hangfire.Mongo.Sample.CosmosDB/Hangfire.Mongo.Sample.CosmosDB.csproj b/src/Hangfire.Mongo.Sample.CosmosDB/Hangfire.Mongo.Sample.CosmosDB.csproj index c79a582..92fcb05 100644 --- a/src/Hangfire.Mongo.Sample.CosmosDB/Hangfire.Mongo.Sample.CosmosDB.csproj +++ b/src/Hangfire.Mongo.Sample.CosmosDB/Hangfire.Mongo.Sample.CosmosDB.csproj @@ -2,7 +2,7 @@ net6.0 - 1.9.13 + 1.9.14 MongoDB storage implementation for Hangfire (background job system for ASP.NET applications). Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau Sergey Zwezdin, Martin Lobger, Jonas Gottschau diff --git a/src/Hangfire.Mongo.Sample.NETCore/Hangfire.Mongo.Sample.NETCore.csproj b/src/Hangfire.Mongo.Sample.NETCore/Hangfire.Mongo.Sample.NETCore.csproj index 8cbff70..ffab5a6 100644 --- a/src/Hangfire.Mongo.Sample.NETCore/Hangfire.Mongo.Sample.NETCore.csproj +++ b/src/Hangfire.Mongo.Sample.NETCore/Hangfire.Mongo.Sample.NETCore.csproj @@ -4,7 +4,7 @@ Hangfire.Mongo.Sample.NETCore Exe Hangfire.Mongo.Sample.NETCore - 1.9.13 + 1.9.14 MongoDB storage implementation for Hangfire (background job system for ASP.NET applications). Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau Sergey Zwezdin, Martin Lobger, Jonas Gottschau diff --git a/src/Hangfire.Mongo.Tests/Migration/Hangfire-Mongo-Schema-021.zip b/src/Hangfire.Mongo.Tests/Migration/Hangfire-Mongo-Schema-021.zip new file mode 100644 index 0000000000000000000000000000000000000000..bfccb32c2ae938923be1a82dd69a829002238190 GIT binary patch literal 2953 zcmZ{m2{=^i8^9-_Xd)S;vW@HpV{9d|B!(G=h$P!ImZmI&aA~n-9a|$a^e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bx-#Z}id04=>=xl%dD$G7xS($(R%N!3)$RA7xlz$zyTh{{54WWHpqcB-Lm#iSt3d zy@J%*cIPak5G5=k@iD;$c9 zXL><(YEm`#tMa=eIG7Y6UPFaB&Q6O;4k>)ackqBj{6YTd5SueH?s9LvFlk!~B@m`UsQw@!j=m`|z8v z^elbp2$<`z0|s-d;k@0=q_m*@UreEdr=;0j2UI^{E#QdnfGCNGsHsZ6Xo4!FECERr zv`1Cx@%E&UtR-K*45{eMLPjMnG1=e%DlgJV=<7Ms6MKW;YF>D|X0e<`!{wa(<+P@w z@Y5oD@JuthWTKuZS~sD<7iQM+K@vz5+usZ3fk&FI9fOk|_#M;wqa!LTD)tCX0IZZo zc5XZs)8&vPBpWcK6sr4B3_FHbKRa+&EgCVhafUcrX}S7`pHT6P%wf~I)s<30&#S;x zK$ezj3w0yid3flgbCl6*{;6W8iMKhoML%8ml2rZm^Yr7__B|rk>Gtw4K{EV7J#+eg zhK)ZWxP%GB6c&zE+;TnNoNW+(B!ab6u)f;dHrE{6g<2HaQw8JA?gqI>%!jvXksjHG zHJ%-9v%qq#l;Qp+sfd6UqdK3}TDcduo2RhAaRi8a$fztK0lH_<@upDOfZI4d#&uZD zx0RNjso49myv-77vZ|MrN9qvD^Bdx`AU-M=d;5T3C$17!}cg74murvFO zeguduCAM`0e9s%yP2-I;02z$ii+(iE6`gv6&(h76v^SzCf&-^4 zz0z_8Ir|%nSna{RF5JxCok|X`Rwmph1v|?L(S~nE;XwUVL(JeU;|BN2BJYqCd?wcw z+M;knT7uc>iImn?ZnCUCtPjS?ET~u;na@dP#40@{=qrM}V!EQMLLzUit6cwW;{WMQ zKE8q89^UBh>h#YKBy91f9UP$V3-o)lV~@1u_%Rn-JP&2@D`9&YKf9l2-~J%{TjsWd zwoBYk(7mmoUzBb;V|x|;WJvGcl1#wQn%qv { - "hangfire.migrationLock" + "hangfire.migrationLock", + "hangfire.notifications" }; if (MongoMigrationManager.RequiredSchemaVersion >= MongoSchema.Version09 && diff --git a/src/Hangfire.Mongo.Tests/Migration/Version20MigrationStepFacts.cs b/src/Hangfire.Mongo.Tests/Migration/Version20MigrationStepFacts.cs index 0ec410f..2a29870 100644 --- a/src/Hangfire.Mongo.Tests/Migration/Version20MigrationStepFacts.cs +++ b/src/Hangfire.Mongo.Tests/Migration/Version20MigrationStepFacts.cs @@ -15,13 +15,11 @@ namespace Hangfire.Mongo.Tests.Migration public class Version20MigrationStepFacts { private readonly IMongoDatabase _database; - private readonly Random _random; private readonly IMongoMigrationStep _migration; public Version20MigrationStepFacts(MongoDbFixture fixture) { var dbContext = fixture.CreateDbContext(); _database = dbContext.Database; - _random = new Random(); _migration = new RemoveJobQueueDto(); } diff --git a/src/Hangfire.Mongo/Hangfire.Mongo.csproj b/src/Hangfire.Mongo/Hangfire.Mongo.csproj index 0979c75..d8fdc6a 100644 --- a/src/Hangfire.Mongo/Hangfire.Mongo.csproj +++ b/src/Hangfire.Mongo/Hangfire.Mongo.csproj @@ -1,6 +1,6 @@ - 1.9.13 + 1.9.14 netstandard2.0 $(NoWarn);CS0618 true @@ -22,7 +22,7 @@ MongoDB storage implementation for Hangfire (background job system for ASP.NET applications). Hangfire AspNet OWIN MongoDB CosmosDB Long-Running Background Fire-And-Forget Delayed Recurring Tasks Jobs Scheduler Threading Queues 1.9.13 - - Improve performance of MongoMonitoringApi.GetQueues() + - Add index needed for improved performance of MongoMonitoringApi.GetQueues README.md diff --git a/src/Hangfire.Mongo/Migration/MongoSchemaExtensions.cs b/src/Hangfire.Mongo/Migration/MongoSchemaExtensions.cs index b2d49a0..615d0bb 100644 --- a/src/Hangfire.Mongo/Migration/MongoSchemaExtensions.cs +++ b/src/Hangfire.Mongo/Migration/MongoSchemaExtensions.cs @@ -124,33 +124,10 @@ public static IList CollectionNames(this MongoSchema schema, string pref prefix + ".server" }; case MongoSchema.Version17: - return new[] - { - prefix + ".jobGraph", - prefix + ".locks", - prefix + ".schema", - prefix + ".server", - prefix + ".notifications" - }; case MongoSchema.Version18: - return new[] - { - prefix + ".jobGraph", - prefix + ".locks", - prefix + ".schema", - prefix + ".server", - prefix + ".notifications" - }; case MongoSchema.Version19: - return new[] - { - prefix + ".jobGraph", - prefix + ".locks", - prefix + ".schema", - prefix + ".server", - prefix + ".notifications" - }; case MongoSchema.Version20: + case MongoSchema.Version21: return new[] { prefix + ".jobGraph", diff --git a/src/Hangfire.Mongo/Migration/Steps/Version22/00_AddQueueIndex.cs b/src/Hangfire.Mongo/Migration/Steps/Version22/00_AddQueueIndex.cs new file mode 100644 index 0000000..1e02eff --- /dev/null +++ b/src/Hangfire.Mongo/Migration/Steps/Version22/00_AddQueueIndex.cs @@ -0,0 +1,21 @@ +using MongoDB.Bson; +using MongoDB.Driver; + +namespace Hangfire.Mongo.Migration.Steps.Version22; + +internal class AddQueueIndex : IndexMigration, IMongoMigrationStep +{ + public MongoSchema TargetSchema => MongoSchema.Version22; + public long Sequence => 0; + public bool Execute(IMongoDatabase database, MongoStorageOptions storageOptions, IMongoMigrationContext migrationContext) + { + var jobGraph = database.GetCollection($"{storageOptions.Prefix}.jobGraph"); + + // "{ _t: 1, Queue: 1 }" + var index = Builders.IndexKeys.Ascending("_t").Ascending("Queue"); + var options = new CreateIndexOptions { Name = "T_Queue" }; + + jobGraph.Indexes.CreateOne(index, options); + return true; + } +} \ No newline at end of file diff --git a/src/Hangfire.Mongo/MongoSchema.cs b/src/Hangfire.Mongo/MongoSchema.cs index 52466a9..b3ab1a5 100644 --- a/src/Hangfire.Mongo/MongoSchema.cs +++ b/src/Hangfire.Mongo/MongoSchema.cs @@ -99,7 +99,12 @@ public enum MongoSchema /// /// Schema Version 21 /// - Version21 = 21 + Version21 = 21, + + /// + /// Schema Version 22 + /// + Version22 = 22 } } \ No newline at end of file