[backend/core] Fix entity reloading from database
This commit is contained in:
parent
1a86ea990a
commit
18bcba7e30
3 changed files with 22 additions and 2 deletions
|
@ -1139,6 +1139,20 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
|||
});
|
||||
}
|
||||
|
||||
public async Task ReloadEntityAsync(object entity)
|
||||
{
|
||||
await Entry(entity).ReloadAsync();
|
||||
}
|
||||
|
||||
public async Task ReloadEntityRecursiveAsync(object entity)
|
||||
{
|
||||
await ReloadEntityAsync(entity);
|
||||
await Entry(entity)
|
||||
.References.Where(p => p is { IsLoaded: true, TargetEntry: not null })
|
||||
.Select(p => p.TargetEntry!.ReloadAsync())
|
||||
.AwaitAllAsync();
|
||||
}
|
||||
|
||||
public IQueryable<Note> NoteAncestors(string noteId, int depth)
|
||||
=> FromExpression(() => NoteAncestors(noteId, depth));
|
||||
|
||||
|
|
|
@ -236,6 +236,9 @@ public class UserResolver(
|
|||
logger.LogError("UpdateUserAsync for user {user} failed with {error}", user.Uri, e.Message);
|
||||
}
|
||||
|
||||
return success ? await db.Users.IncludeCommonProperties().FirstAsync(p => p.Id == user.Id) : user;
|
||||
if (success)
|
||||
await db.ReloadEntityRecursiveAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
|
@ -781,6 +781,9 @@ public class UserService(
|
|||
|
||||
await task.SafeWaitAsync(TimeSpan.FromMilliseconds(500));
|
||||
|
||||
return success ? await db.Users.IncludeCommonProperties().FirstAsync(p => p.Id == user.Id) : user;
|
||||
if (success)
|
||||
await db.ReloadEntityRecursiveAsync(user);
|
||||
|
||||
return user;
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue