Skip to content

Commit

Permalink
Merge branch 'hotfix/v2.0.2' of github.com:ONLYOFFICE/DocSpace-server…
Browse files Browse the repository at this point in the history
… into hotfix/v2.0.2
  • Loading branch information
alexeybannov committed Jan 25, 2024
2 parents ca4c2ec + 339e56b commit 4b67470
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 66 deletions.
20 changes: 0 additions & 20 deletions common/ASC.Data.Backup.Core/Tasks/BackupPortalTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,26 +123,6 @@ private async Task DoDump(IDataWriteOperator writer)
{
var databases = new Dictionary<Tuple<string, string>, List<string>>();

try
{
await using var connection = DbFactory.OpenConnection();
var command = connection.CreateCommand();
command.CommandText = "select id, connection_string from mail_server_server";
ExecuteList(command).ForEach(r =>
{
var connectionString = GetConnectionString((int)r[0], JsonConvert.DeserializeObject<Dictionary<string, object>>(Convert.ToString(r[1]))["DbConnection"].ToString());

var command = connection.CreateCommand();
command.CommandText = "show tables";
var tables = ExecuteList(command).Select(r => Convert.ToString(r[0])).ToList();
databases.Add(new Tuple<string, string>(connectionString.Name, connectionString.ConnectionString), tables);
});
}
catch (Exception e)
{
_logger.ErrorWithException(e);
}

await using (var connection = DbFactory.OpenConnection())
{
var command = connection.CreateCommand();
Expand Down
15 changes: 0 additions & 15 deletions common/ASC.Data.Backup.Core/Tasks/RestorePortalTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -213,21 +213,6 @@ private async Task RestoreFromDump(IDataReadOperator dataReader)

Task.WaitAll(tasks.ToArray());
}
try
{
await using var connection = DbFactory.OpenConnection();
var command = connection.CreateCommand();
command.CommandText = "select id, connection_string from mail_server_server";
ExecuteList(command).ForEach(r =>
{
var connectionString = GetConnectionString((int)r[0], JsonConvert.DeserializeObject<Dictionary<string, object>>(Convert.ToString(r[1]))["DbConnection"].ToString());
databases.Add(new Tuple<string, string>(connectionString.Name, connectionString.ConnectionString), databasesFromDirs[connectionString.Name]);
});
}
catch (Exception e)
{
_logger.ErrorWithException(e);
}

foreach (var database in databases)
{
Expand Down
39 changes: 22 additions & 17 deletions common/services/ASC.ElasticSearch/Engine/BaseIndexer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,18 @@ public BaseIndexer(
_serviceProvider = serviceProvider;
}

public async Task<IEnumerable<List<T>>> IndexAllAsync(
public async IAsyncEnumerable<List<T>> IndexAllAsync(
Func<DateTime, (int, int, int)> getCount,
Func<DateTime, List<int>> getIds,
Func<long, long, DateTime, List<T>> getData)
{
await using var webstudioDbContext = await _dbContextFactory.CreateDbContextAsync();
{
var now = DateTime.UtcNow;
var lastIndexed = await Queries.LastIndexedAsync(webstudioDbContext, Wrapper.IndexName);
DateTime lastIndexed;

await using (var webStudioDbContext = await _dbContextFactory.CreateDbContextAsync())
{
lastIndexed = await Queries.LastIndexedAsync(webStudioDbContext, Wrapper.IndexName);
}

if (lastIndexed.Equals(DateTime.MinValue))
{
Expand All @@ -111,26 +115,27 @@ public async Task<IEnumerable<List<T>>> IndexAllAsync(
var (count, max, min) = getCount(lastIndexed);
_logger.DebugIndex(IndexName, count, max, min);

var ids = new List<int>() { min };
var ids = new List<int> { min };
ids.AddRange(getIds(lastIndexed));
ids.Add(max);

for (var i = 0; i < ids.Count - 1; i++)
{
yield return getData(ids[i], ids[i + 1], lastIndexed);
}

await webstudioDbContext.AddOrUpdateAsync(q => q.WebstudioIndex, new DbWebstudioIndex()
await using (var webStudioDbContext = await _dbContextFactory.CreateDbContextAsync())
{
IndexName = Wrapper.IndexName,
LastModified = now
});
await webStudioDbContext.AddOrUpdateAsync(q => q.WebstudioIndex, new DbWebstudioIndex
{
IndexName = Wrapper.IndexName,
LastModified = now
});

await webstudioDbContext.SaveChangesAsync();
await webStudioDbContext.SaveChangesAsync();
}

_logger.DebugIndexCompleted(Wrapper.IndexName);

var list = new List<List<T>>();
for (var i = 0; i < ids.Count - 1; i++)
{
list.Add(getData(ids[i], ids[i + 1], lastIndexed));
}
return list;
}

public async Task ReIndrexAsync()
Expand Down
19 changes: 7 additions & 12 deletions products/ASC.Files/Core/Core/Dao/TeamlabDao/FileDao.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1575,22 +1575,17 @@ select f
}

protected internal async Task<DbFile> InitDocumentAsync(DbFile dbFile)
{
{
dbFile.Document = new Document
{
Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(""))
};

if (!await _factoryIndexer.CanIndexByContentAsync(dbFile))
{
dbFile.Document = new Document
{
Data = Convert.ToBase64String(Encoding.UTF8.GetBytes(""))
};

return dbFile;
}

return await InternalInitDocumentAsync(dbFile);
}

private async Task<DbFile> InternalInitDocumentAsync(DbFile dbFile)
{

var file = _serviceProvider.GetService<File<int>>();
file.Id = dbFile.Id;
file.Title = dbFile.Title;
Expand Down
4 changes: 3 additions & 1 deletion products/ASC.Files/Core/Core/Search/FactoryIndexerFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public override async Task IndexAllAsync()
var j = 0;
var tasks = new List<Task>();

foreach (var data in await _indexer.IndexAllAsync(GetCount, GetIds, GetData))
await foreach (var data in _indexer.IndexAllAsync(GetCount, GetIds, GetData))
{
if (_settings.Threads == 1)
{
Expand Down Expand Up @@ -125,6 +125,8 @@ public override async Task IndexAllAsync()
throw;
}

return;

List<int> GetIds(DateTime lastIndexed)
{
var start = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ List<int> getIds(DateTime lastIndexed)
var j = 0;
var tasks = new List<Task>();

foreach (var data in await _indexer.IndexAllAsync(getCount, getIds, getData))
await foreach (var data in _indexer.IndexAllAsync(getCount, getIds, getData))
{
if (_settings.Threads == 1)
{
Expand Down

0 comments on commit 4b67470

Please sign in to comment.