mirror of
https://github.com/streetwriters/notesnook-sync-server.git
synced 2026-02-12 11:12:44 +00:00
db: increase heartbeat interval to 60 seconds
This commit is contained in:
@@ -17,14 +17,14 @@ You should have received a copy of the Affero GNU General Public License
|
|||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
using Microsoft.Extensions.Configuration;
|
|
||||||
using MongoDB.Driver;
|
|
||||||
using Streetwriters.Data.Interfaces;
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
using Microsoft.Extensions.Configuration;
|
||||||
|
using MongoDB.Driver;
|
||||||
|
using Streetwriters.Data.Interfaces;
|
||||||
|
|
||||||
namespace Streetwriters.Data.DbContexts
|
namespace Streetwriters.Data.DbContexts
|
||||||
{
|
{
|
||||||
@@ -35,15 +35,22 @@ namespace Streetwriters.Data.DbContexts
|
|||||||
var settings = MongoClientSettings.FromConnectionString(dbSettings.ConnectionString);
|
var settings = MongoClientSettings.FromConnectionString(dbSettings.ConnectionString);
|
||||||
settings.MaxConnectionPoolSize = 500;
|
settings.MaxConnectionPoolSize = 500;
|
||||||
settings.MinConnectionPoolSize = 0;
|
settings.MinConnectionPoolSize = 0;
|
||||||
|
settings.HeartbeatInterval = TimeSpan.FromSeconds(60);
|
||||||
return new MongoClient(settings);
|
return new MongoClient(settings);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IMongoCollection<T> GetMongoCollection<T>(IMongoClient client, string databaseName, string collectionName)
|
public static IMongoCollection<T> GetMongoCollection<T>(
|
||||||
|
IMongoClient client,
|
||||||
|
string databaseName,
|
||||||
|
string collectionName
|
||||||
|
)
|
||||||
{
|
{
|
||||||
return client.GetDatabase(databaseName).GetCollection<T>(collectionName, new MongoCollectionSettings()
|
return client
|
||||||
{
|
.GetDatabase(databaseName)
|
||||||
AssignIdOnInsert = true,
|
.GetCollection<T>(
|
||||||
});
|
collectionName,
|
||||||
|
new MongoCollectionSettings() { AssignIdOnInsert = true }
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly List<Func<IClientSessionHandle, CancellationToken, Task>> _commands = [];
|
private readonly List<Func<IClientSessionHandle, CancellationToken, Task>> _commands = [];
|
||||||
@@ -59,13 +66,14 @@ namespace Streetwriters.Data.DbContexts
|
|||||||
#if (DEBUG || STAGING)
|
#if (DEBUG || STAGING)
|
||||||
await Parallel.ForEachAsync(_commands, async (c, ct) => await c(session, ct));
|
await Parallel.ForEachAsync(_commands, async (c, ct) => await c(session, ct));
|
||||||
#else
|
#else
|
||||||
await session.WithTransactionAsync(async (handle, token) =>
|
await session.WithTransactionAsync(
|
||||||
{
|
async (handle, token) =>
|
||||||
await Task.WhenAll(_commands.Select(c => c(handle, token)));
|
{
|
||||||
return true;
|
await Task.WhenAll(_commands.Select(c => c(handle, token)));
|
||||||
});
|
return true;
|
||||||
|
}
|
||||||
|
);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
}
|
}
|
||||||
return count;
|
return count;
|
||||||
}
|
}
|
||||||
@@ -87,4 +95,4 @@ namespace Streetwriters.Data.DbContexts
|
|||||||
GC.SuppressFinalize(this);
|
GC.SuppressFinalize(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user