Skip to content

Commit

Permalink
#442 tag category poems with sources
Browse files Browse the repository at this point in the history
  • Loading branch information
hrmoh committed Jun 17, 2024
1 parent 6aafd19 commit cf8f12f
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
15 changes: 15 additions & 0 deletions RMuseum/RMuseum.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3941,6 +3941,18 @@
<member name="M:RMuseum.Migrations.PaperSources.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="T:RMuseum.Migrations.SureNameFix">
<inheritdoc />
</member>
<member name="M:RMuseum.Migrations.SureNameFix.Up(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:RMuseum.Migrations.SureNameFix.Down(Microsoft.EntityFrameworkCore.Migrations.MigrationBuilder)">
<inheritdoc />
</member>
<member name="M:RMuseum.Migrations.SureNameFix.BuildTargetModel(Microsoft.EntityFrameworkCore.ModelBuilder)">
<inheritdoc />
</member>
<member name="T:RMuseum.Models.Accounting.DonationExpenditure">
<summary>
donation expenditures
Expand Down Expand Up @@ -17864,6 +17876,9 @@
<summary>
IGanjoorService implementation
</summary>
<summary>
IGanjoorService implementation
</summary>
</member>
<member name="M:RMuseum.Services.Implementation.GanjoorService.SwitchCoupletBookmark(System.Guid,System.Int32,System.Int32)">
<summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
using Microsoft.EntityFrameworkCore;
using RMuseum.Models.Ganjoor;
using RSecurityBackend.Models.Generic;
using System;
using System.Data;
using System.Linq;
using RMuseum.DbContext;
using System.Collections.Generic;
using RSecurityBackend.Services.Implementation;

namespace RMuseum.Services.Implementation
{
/// <summary>
/// IGanjoorService implementation
/// </summary>
public partial class GanjoorService : IGanjoorService
{
public void TagCategoryWithSource(int catId, string sourceUrlSlug)
{
_backgroundTaskQueue.QueueBackgroundWorkItem
(
async token =>
{
using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions<RMuseumDbContext>())) //this is long running job, so _context might be already been freed/collected by GC
{
LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context);
var job = (await jobProgressServiceEF.NewJob($"TagCategoryWithSource(catId: {catId} - source:{sourceUrlSlug})", "Query data")).Result;
try
{
var page = await context.GanjoorPages.AsNoTracking().Where(p => p.FullUrl == $"/sources/{sourceUrlSlug}").SingleOrDefaultAsync();
if(page == null)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, $"Page not found : /sources/{sourceUrlSlug}");
}
string sourceName = page.Title;
switch(sourceUrlSlug)
{
case "wikidorj":
sourceName = "ویکی‌درج";
break;
case "frankfurt":
sourceName = "دانشگاه فرانکفورت";
break;
case "tariqmo":
sourceName = "طریق التحقیق دکتر مؤذنی";
break;
case "tebyan":
sourceName = "تبیان";
break;
}
List<int> catIdList = new List<int>
{
catId
};
await _populateCategoryChildren(context, catId, catIdList);
int poemCount = 0;
int progress = 0;
foreach (int catId in catIdList)
{
var poems = await context.GanjoorPoems.AsNoTracking().Where(p => p.CatId == catId).ToListAsync();
poemCount += poems.Count;
foreach (var poem in poems)
{
poem.SourceName = sourceName;
poem.SourceUrlSlug = sourceUrlSlug;
context.Update(poem);
await jobProgressServiceEF.UpdateJob(job.Id, progress, $"{progress} از {poemCount}");
}
}
}
catch (Exception exp)
{
await jobProgressServiceEF.UpdateJob(job.Id, 100, "", false, exp.ToString());
}
}
});
}
}
}

0 comments on commit cf8f12f

Please sign in to comment.