Skip to content

Commit

Permalink
fix(pm): fix crash when reading private messages (#191)
Browse files Browse the repository at this point in the history
* fix(pm): fix crash when reading private messages

* fix(pm): re-enable DBContext pooling
  • Loading branch information
Rain336 authored Aug 29, 2024
1 parent d6895ef commit 33e41d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ public class PrivateMessageService : EntityServiceBase<PrivateMessageRecord>, IP
private readonly AppDbContext _appDbContext;
private readonly IFirebaseChannelManager _firebaseChannelManager;

private readonly ConcurrentQueue<QueuedNotificationParameters> _notificationQueue =
new ConcurrentQueue<QueuedNotificationParameters>();
private readonly ConcurrentQueue<QueuedNotificationParameters> _notificationQueue = new();

public PrivateMessageService(
AppDbContext appDbContext,
Expand All @@ -37,7 +36,7 @@ public async Task<List<PrivateMessageRecord>> GetPrivateMessagesForRecipientAsyn
string identityId,
CancellationToken cancellationToken = default)
{
var messages = await _appDbContext.PrivateMessages.AsNoTracking()
var messages = await _appDbContext.PrivateMessages
.Where(msg =>
(regSysIds.Contains(msg.RecipientRegSysId) || msg.RecipientIdentityId == identityId) &&
msg.IsDeleted == 0)
Expand All @@ -51,10 +50,11 @@ public async Task<List<PrivateMessageRecord>> GetPrivateMessagesForRecipientAsyn
foreach (var message in messages.Where(a => !a.ReceivedDateTimeUtc.HasValue))
{
message.ReceivedDateTimeUtc = DateTime.UtcNow;
message.Touch();
}

await ReplaceMultipleAsync(messages, cancellationToken);

await _appDbContext.SaveChangesAsync(cancellationToken);
return messages;
}

Expand Down Expand Up @@ -185,6 +185,7 @@ public async Task<List<PrivateMessageRecord>> GetPrivateMessagesForSenderAsync(
CancellationToken cancellationToken = default)
{
return await _appDbContext.PrivateMessages
.AsNoTracking()
.Where(a => a.SenderUid == senderUid)
.ToListAsync(cancellationToken);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ private async Task UpdateRegSysIdsInDb(List<string> ids, string identityId)
var newIds = new HashSet<string>(ids);

var existingIds = await db.RegistrationIdentities
.AsNoTracking()
.Where(x => newIds.Contains(x.RegSysId))
.Select(x => x.RegSysId)
.ToListAsync();
Expand Down

0 comments on commit 33e41d9

Please sign in to comment.