Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add index #373

Merged
merged 1 commit into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -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()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description />
<Version>1.9.13</Version>
<Version>1.9.14</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<Description />
<Version>1.9.13</Version>
<Version>1.9.14</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<AssemblyName>Hangfire.Mongo.Sample.NETCore</AssemblyName>
<OutputType>Exe</OutputType>
<PackageId>Hangfire.Mongo.Sample.NETCore</PackageId>
<Version>1.9.13</Version>
<Version>1.9.14</Version>
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<Copyright>Copyright © 2014-2019 Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Copyright>
<Authors>Sergey Zwezdin, Martin Lobger, Jonas Gottschau</Authors>
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public void Clean_Database_Filled()
MigrationStrategy = new DropMongoMigrationStrategy(),
BackupStrategy = new NoneMongoBackupStrategy()
},
CheckQueuedJobsStrategy = CheckQueuedJobsStrategy.TailNotificationsCollection,
QueuePollInterval = TimeSpan.FromMilliseconds(500)
};
var serverOptions = new BackgroundJobServerOptions
Expand Down Expand Up @@ -94,7 +95,8 @@ public void Clean_Database_Filled()
{
var allowedEmptyCollections = new List<string>
{
"hangfire.migrationLock"
"hangfire.migrationLock",
"hangfire.notifications"
};

if (MongoMigrationManager.RequiredSchemaVersion >= MongoSchema.Version09 &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down
4 changes: 2 additions & 2 deletions src/Hangfire.Mongo/Hangfire.Mongo.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<VersionPrefix>1.9.13</VersionPrefix>
<VersionPrefix>1.9.14</VersionPrefix>
<TargetFramework>netstandard2.0</TargetFramework>
<NoWarn>$(NoWarn);CS0618</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand All @@ -22,7 +22,7 @@
<Description>MongoDB storage implementation for Hangfire (background job system for ASP.NET applications).</Description>
<PackageTags>Hangfire AspNet OWIN MongoDB CosmosDB Long-Running Background Fire-And-Forget Delayed Recurring Tasks Jobs Scheduler Threading Queues</PackageTags>
<PackageReleaseNotes>1.9.13
- Improve performance of MongoMonitoringApi.GetQueues()
- Add index needed for improved performance of MongoMonitoringApi.GetQueues
</PackageReleaseNotes>
<PackageReadmeFile>README.md</PackageReadmeFile>
<!--<PackageLicenseUrl>https://raw.githubusercontent.com/sergun/Hangfire.Mongo/master/LICENSE</PackageLicenseUrl>-->
Expand Down
25 changes: 1 addition & 24 deletions src/Hangfire.Mongo/Migration/MongoSchemaExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,33 +124,10 @@ public static IList<string> 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",
Expand Down
21 changes: 21 additions & 0 deletions src/Hangfire.Mongo/Migration/Steps/Version22/00_AddQueueIndex.cs
Original file line number Diff line number Diff line change
@@ -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<BsonDocument>($"{storageOptions.Prefix}.jobGraph");

// "{ _t: 1, Queue: 1 }"
var index = Builders<BsonDocument>.IndexKeys.Ascending("_t").Ascending("Queue");
var options = new CreateIndexOptions { Name = "T_Queue" };

jobGraph.Indexes.CreateOne(index, options);
return true;
}
}
7 changes: 6 additions & 1 deletion src/Hangfire.Mongo/MongoSchema.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ public enum MongoSchema
/// <summary>
/// Schema Version 21
/// </summary>
Version21 = 21
Version21 = 21,

/// <summary>
/// Schema Version 22
/// </summary>
Version22 = 22
}

}