✨ Cache user social credits on profile
This commit is contained in:
@@ -135,9 +135,20 @@ public class AccountProfile : ModelBase, IIdentifiedResource
|
||||
[Column(TypeName = "jsonb")] public VerificationMark? Verification { get; set; }
|
||||
[Column(TypeName = "jsonb")] public BadgeReferenceObject? ActiveBadge { get; set; }
|
||||
|
||||
public int Experience { get; set; } = 0;
|
||||
public int Experience { get; set; }
|
||||
[NotMapped] public int Level => Leveling.ExperiencePerLevel.Count(xp => Experience >= xp) - 1;
|
||||
|
||||
public double SocialCredits { get; set; }
|
||||
|
||||
[NotMapped]
|
||||
public int SocialCreditsLevel => SocialCredits switch
|
||||
{
|
||||
< 100 => -1,
|
||||
> 100 and < 200 => 0,
|
||||
< 200 => 1,
|
||||
_ => 2
|
||||
};
|
||||
|
||||
[NotMapped]
|
||||
public double LevelingProgress => Level >= Leveling.ExperiencePerLevel.Count - 1
|
||||
? 100
|
||||
@@ -168,6 +179,8 @@ public class AccountProfile : ModelBase, IIdentifiedResource
|
||||
Experience = Experience,
|
||||
Level = Level,
|
||||
LevelingProgress = LevelingProgress,
|
||||
SocialCredits = SocialCredits,
|
||||
SocialCreditsLevel = SocialCreditsLevel,
|
||||
Picture = Picture?.ToProtoValue(),
|
||||
Background = Background?.ToProtoValue(),
|
||||
AccountId = AccountId.ToString(),
|
||||
@@ -198,6 +211,7 @@ public class AccountProfile : ModelBase, IIdentifiedResource
|
||||
Verification = proto.Verification is null ? null : VerificationMark.FromProtoValue(proto.Verification),
|
||||
ActiveBadge = proto.ActiveBadge is null ? null : BadgeReferenceObject.FromProtoValue(proto.ActiveBadge),
|
||||
Experience = proto.Experience,
|
||||
SocialCredits = proto.SocialCredits,
|
||||
Picture = proto.Picture is null ? null : CloudFileReferenceObject.FromProtoValue(proto.Picture),
|
||||
Background = proto.Background is null ? null : CloudFileReferenceObject.FromProtoValue(proto.Background),
|
||||
AccountId = Guid.Parse(proto.AccountId),
|
||||
|
@@ -18,6 +18,13 @@ public class SocialCreditService(AppDatabase db, ICacheService cache)
|
||||
};
|
||||
db.SocialCreditRecords.Add(record);
|
||||
await db.SaveChangesAsync();
|
||||
|
||||
await db.AccountProfiles
|
||||
.Where(p => p.AccountId == accountId)
|
||||
.ExecuteUpdateAsync(p => p.SetProperty(v => v.SocialCredits, v => v.SocialCredits + record.Delta));
|
||||
|
||||
await cache.RemoveAsync($"{CacheKeyPrefix}{accountId}");
|
||||
|
||||
return record;
|
||||
}
|
||||
|
||||
@@ -32,6 +39,7 @@ public class SocialCreditService(AppDatabase db, ICacheService cache)
|
||||
.Where(x => x.AccountId == accountId)
|
||||
.SumAsync(x => x.Delta);
|
||||
records += BaseSocialCredit;
|
||||
|
||||
await cache.SetAsync($"{CacheKeyPrefix}{accountId}", records);
|
||||
return records;
|
||||
}
|
||||
|
@@ -462,6 +462,10 @@ namespace DysonNetwork.Pass.Migrations
|
||||
.HasColumnType("character varying(1024)")
|
||||
.HasColumnName("pronouns");
|
||||
|
||||
b.Property<double>("SocialCredits")
|
||||
.HasColumnType("double precision")
|
||||
.HasColumnName("social_credits");
|
||||
|
||||
b.Property<string>("TimeZone")
|
||||
.HasMaxLength(1024)
|
||||
.HasColumnType("character varying(1024)")
|
||||
|
@@ -75,6 +75,8 @@ message AccountProfile {
|
||||
int32 experience = 14;
|
||||
int32 level = 15;
|
||||
double leveling_progress = 16;
|
||||
double social_credits = 17;
|
||||
int32 social_credits_level = 18;
|
||||
|
||||
CloudFile picture = 19;
|
||||
CloudFile background = 20;
|
||||
|
Reference in New Issue
Block a user