|
2 | 2 |
|
3 | 3 | namespace tbm.Crawler.Tieba.Crawl.Saver; |
4 | 4 |
|
5 | | -public class SaverChangeSet<TPost> where TPost : class, IPost |
| 5 | +public class SaverChangeSet<TPost>( |
| 6 | + IReadOnlyCollection<TPost> existingBefore, |
| 7 | + ICollection<TPost> existingAfterAndNewlyAdded, |
| 8 | + Func<TPost, PostId> postIdSelector) |
| 9 | + where TPost : class, IPost |
6 | 10 | { |
7 | | - public SaverChangeSet( |
8 | | - IReadOnlyCollection<TPost> existingBefore, |
9 | | - ICollection<TPost> existingAfterAndNewlyAdded, |
10 | | - Func<TPost, PostId> postIdSelector) |
11 | | - { |
12 | | - Existing = existingBefore |
13 | | - .OrderBy(postIdSelector) |
14 | | - .EquiZip(existingAfterAndNewlyAdded |
| 11 | + public IReadOnlyCollection<(TPost Before, TPost After)> Existing { get; } = existingBefore |
| 12 | + .OrderBy(postIdSelector) |
| 13 | + .EquiZip(existingAfterAndNewlyAdded |
15 | 14 | .IntersectBy(existingBefore.Select(postIdSelector), postIdSelector) |
16 | 15 | .OrderBy(postIdSelector), |
17 | | - (before, after) => (before, after)) |
18 | | - .ToList().AsReadOnly(); |
19 | | - NewlyAdded = existingAfterAndNewlyAdded |
20 | | - .ExceptBy(existingBefore.Select(postIdSelector), postIdSelector) |
21 | | - .ToList().AsReadOnly(); |
22 | | - AllAfter = existingAfterAndNewlyAdded.ToList().AsReadOnly(); |
23 | | - } |
| 16 | + (before, after) => (before, after)) |
| 17 | + .ToList().AsReadOnly(); |
24 | 18 |
|
25 | | - public IReadOnlyCollection<(TPost Before, TPost After)> Existing { get; } |
26 | | - public IReadOnlyCollection<TPost> NewlyAdded { get; } |
27 | | - public IReadOnlyCollection<TPost> AllAfter { get; } |
| 19 | + public IReadOnlyCollection<TPost> NewlyAdded { get; } = existingAfterAndNewlyAdded |
| 20 | + .ExceptBy(existingBefore.Select(postIdSelector), postIdSelector) |
| 21 | + .ToList().AsReadOnly(); |
| 22 | + |
| 23 | + public IReadOnlyCollection<TPost> AllAfter { get; } = existingAfterAndNewlyAdded |
| 24 | + .ToList().AsReadOnly(); |
28 | 25 | } |
0 commit comments