💄 Optimize settle publisher service logic
This commit is contained in:
		@@ -574,6 +574,10 @@ public class PublisherService(
 | 
				
			|||||||
        var date = now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
 | 
					        var date = now.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        var publisherIds = publisherStats.Keys.ToList();
 | 
					        var publisherIds = publisherStats.Keys.ToList();
 | 
				
			||||||
 | 
					        var publishers = await db.Publishers
 | 
				
			||||||
 | 
					            .Where(p => publisherIds.Contains(p.Id))
 | 
				
			||||||
 | 
					            .Select(p => new { p.Id, p.Name })
 | 
				
			||||||
 | 
					            .ToDictionaryAsync(p => p.Id, p => p);
 | 
				
			||||||
        var publisherMembers = await db.PublisherMembers
 | 
					        var publisherMembers = await db.PublisherMembers
 | 
				
			||||||
            .Where(m => publisherIds.Contains(m.PublisherId))
 | 
					            .Where(m => publisherIds.Contains(m.PublisherId))
 | 
				
			||||||
            .ToListAsync();
 | 
					            .ToListAsync();
 | 
				
			||||||
@@ -602,12 +606,14 @@ public class PublisherService(
 | 
				
			|||||||
            if (!publisherAccounts.TryGetValue(publisherId, out var receivers) || receivers.Count == 0)
 | 
					            if (!publisherAccounts.TryGetValue(publisherId, out var receivers) || receivers.Count == 0)
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            var publisherName = publishers.TryGetValue(publisherId, out var pub) ? pub.Name : "unknown";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Use totalExperience for rewarding
 | 
					            // Use totalExperience for rewarding
 | 
				
			||||||
            foreach (var receiver in receivers)
 | 
					            foreach (var receiver in receivers)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await experiences.AddRecordAsync(new AddExperienceRecordRequest
 | 
					                await experiences.AddRecordAsync(new AddExperienceRecordRequest
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Reason = $"Publishing Reward on {date}",
 | 
					                    Reason = $"Publishing Reward on {date} for @{publisherName}",
 | 
				
			||||||
                    ReasonType = "publishers.rewards",
 | 
					                    ReasonType = "publishers.rewards",
 | 
				
			||||||
                    AccountId = receiver.Id.ToString(),
 | 
					                    AccountId = receiver.Id.ToString(),
 | 
				
			||||||
                    Delta = totalExperience,
 | 
					                    Delta = totalExperience,
 | 
				
			||||||
@@ -616,7 +622,8 @@ public class PublisherService(
 | 
				
			|||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Foreach loop through publishers to set social credit
 | 
					        // Foreach loop through publishers to set social credit
 | 
				
			||||||
        var expiredAt = now.InZone(DateTimeZone.Utc).Date.PlusDays(1).AtStartOfDayInZone(DateTimeZone.Utc).Minus(Duration.FromMilliseconds(1)).ToInstant();
 | 
					        var expiredAt = now.InZone(DateTimeZone.Utc).Date.PlusDays(1).AtStartOfDayInZone(DateTimeZone.Utc)
 | 
				
			||||||
 | 
					            .Minus(Duration.FromMilliseconds(1)).ToInstant();
 | 
				
			||||||
        foreach (var (publisherId, value) in publisherStats)
 | 
					        foreach (var (publisherId, value) in publisherStats)
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
            var upvotes = value.Upvotes;
 | 
					            var upvotes = value.Upvotes;
 | 
				
			||||||
@@ -632,12 +639,14 @@ public class PublisherService(
 | 
				
			|||||||
            if (!publisherAccounts.TryGetValue(publisherId, out var receivers) || receivers.Count == 0)
 | 
					            if (!publisherAccounts.TryGetValue(publisherId, out var receivers) || receivers.Count == 0)
 | 
				
			||||||
                continue;
 | 
					                continue;
 | 
				
			||||||
            
 | 
					            
 | 
				
			||||||
 | 
					            var publisherName = publishers.TryGetValue(publisherId, out var pub) ? pub.Name : "unknown";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
            // Set social credit for receivers, expired before next settle
 | 
					            // Set social credit for receivers, expired before next settle
 | 
				
			||||||
            foreach (var receiver in receivers)
 | 
					            foreach (var receiver in receivers)
 | 
				
			||||||
            {
 | 
					            {
 | 
				
			||||||
                await socialCredits.AddRecordAsync(new AddSocialCreditRecordRequest
 | 
					                await socialCredits.AddRecordAsync(new AddSocialCreditRecordRequest
 | 
				
			||||||
                {
 | 
					                {
 | 
				
			||||||
                    Reason = $"Publishing Reward on {date}",
 | 
					                    Reason = $"Publishing Reward on {date} for @{publisherName}",
 | 
				
			||||||
                    ReasonType = "publishers.rewards",
 | 
					                    ReasonType = "publishers.rewards",
 | 
				
			||||||
                    AccountId = receiver.Id.ToString(),
 | 
					                    AccountId = receiver.Id.ToString(),
 | 
				
			||||||
                    Delta = socialCreditDelta,
 | 
					                    Delta = socialCreditDelta,
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user