Skip to content

Commit c5ccffb

Browse files
committed
* fix throwing InvalidCastException: Unable to cast object of type 'System.Linq.Expressions.FieldExpression' to type 'System.Linq.Expressions.LambdaExpression'. at LinqToDB.Linq.Builder.ExpressionBuilder.ConvertSelect() when enumerating variable existingRevisionOfExistingUsers @ AuthorRevisionSaver.Save()
* rename variable and fields with name `ids` to full form plural nouns with suffix `-Id` @ c#/crawler
1 parent e31e1fc commit c5ccffb

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

c#/crawler/src/Tieba/Crawl/Saver/Related/AuthorRevisionSaver.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,9 @@ private Action Save<TEntity, TRevision, TValue>(
5555
revisioningFieldSelector);
5656

5757
SharedHelper.GetNowTimestamp(out var now);
58+
var usersId = uniqueEntities.Select(uidSelector);
5859
var existingRevisionOfExistingUsers = dbSet.AsNoTracking()
59-
.Where(e => e.Fid == db.Fid
60-
&& uniqueEntities.Select(uidSelector).Contains(e.Uid))
60+
.Where(e => e.Fid == db.Fid && usersId.Contains(e.Uid))
6161
.Select(latestRevisionProjectionFactory)
6262
.AsCte() // https://stackoverflow.com/questions/49854322/usage-of-for-update-in-window-function-postgres#comment86726589_49854322
6363
.Where(e => e.Rank == 1)

c#/crawler/src/Tieba/Crawl/Saver/Related/ThreadLatestReplierSaver.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ public class ThreadLatestReplierSaver(
66
SaverLocks<Tid>.New tidSaverLocksFactory)
77
{
88
private static readonly HashSet<UniqueLatestReplier> GlobalLockedLatestRepliers = [];
9-
private static readonly HashSet<Tid> GlobalLockedTids = [];
9+
private static readonly HashSet<Tid> GlobalLockedThreadsId = [];
1010

1111
private readonly Lazy<SaverLocks<UniqueLatestReplier>> _latestReplierSaverLocks =
1212
new(() => latestReplierSaverLocksFactory(GlobalLockedLatestRepliers));
1313
private readonly Lazy<SaverLocks<Tid>> _tidSaverLocks =
14-
new(() => tidSaverLocksFactory(GlobalLockedTids));
14+
new(() => tidSaverLocksFactory(GlobalLockedThreadsId));
1515

1616
public Action SaveFromThread(CrawlerDbContext db, IReadOnlyCollection<ThreadPost> threads)
1717
{

c#/crawler/src/Worker/RetryCrawlWorker.cs

+4-4
Original file line numberDiff line numberDiff line change
@@ -60,18 +60,18 @@ private async Task RetryThreadLate(
6060
CancellationToken stoppingToken = default)
6161
{
6262
await using var threadLateFacade = threadLateCrawlFacadeFactory();
63-
foreach (var tidsGroupByFid in failureCountWithPagesKeyByLockId
63+
foreach (var threadsIdGroupByFid in failureCountWithPagesKeyByLockId
6464
.Keys.GroupBy(lockId => lockId.Fid, lockId => lockId.Tid))
6565
{
66-
var fid = tidsGroupByFid.Key;
66+
var fid = threadsIdGroupByFid.Key;
6767
FailureCount FailureCountSelector(Tid tid) =>
6868

6969
// it should always contain only one page which is 1
7070
failureCountWithPagesKeyByLockId[new(fid, tid)].Single().Value;
71-
var failureCountsKeyByTid = tidsGroupByFid
71+
var failureCountsKeyByTid = threadsIdGroupByFid
7272
.Cast<Tid>().ToDictionary(tid => tid, FailureCountSelector);
7373
logger.LogTrace("Retrying previous failed thread late crawl with fid={}, threadsId={}",
74-
fid, SharedHelper.UnescapedJsonSerialize(tidsGroupByFid));
74+
fid, SharedHelper.UnescapedJsonSerialize(threadsIdGroupByFid));
7575
await threadLateFacade.Value(fid).CrawlThenSave(failureCountsKeyByTid, stoppingToken);
7676
}
7777
}

0 commit comments

Comments
 (0)