🐛 Trying to fix discovery

This commit is contained in:
2025-08-09 23:22:14 +08:00
parent c3f5ed881f
commit 78cec27ef0
3 changed files with 10 additions and 11 deletions

View File

@@ -36,7 +36,7 @@ public class ActivityService(
if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2)) if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2))
{ {
var realms = await ds.GetPublicRealmsAsync(null, 5, 0, true); var realms = await ds.GetCommunityRealmAsync(null, 5, 0, true);
if (realms.Count > 0) if (realms.Count > 0)
{ {
activities.Add(new DiscoveryActivity( activities.Add(new DiscoveryActivity(
@@ -142,7 +142,7 @@ public class ActivityService(
{ {
if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2)) if (cursor == null && (debugInclude.Contains("realms") || Random.Shared.NextDouble() < 0.2))
{ {
var realms = await ds.GetPublicRealmsAsync(null, 5, 0, true); var realms = await ds.GetCommunityRealmAsync(null, 5, 0, true);
if (realms.Count > 0) if (realms.Count > 0)
{ {
activities.Add(new DiscoveryActivity( activities.Add(new DiscoveryActivity(

View File

@@ -13,6 +13,6 @@ public class DiscoveryController(DiscoveryService discoveryService) : Controller
[FromQuery] int offset = 0 [FromQuery] int offset = 0
) )
{ {
return discoveryService.GetPublicRealmsAsync(query, take, offset); return discoveryService.GetCommunityRealmAsync(query, take, offset);
} }
} }

View File

@@ -4,7 +4,7 @@ namespace DysonNetwork.Sphere.Discovery;
public class DiscoveryService(AppDatabase appDatabase) public class DiscoveryService(AppDatabase appDatabase)
{ {
public Task<List<Realm.Realm>> GetPublicRealmsAsync( public Task<List<Realm.Realm>> GetCommunityRealmAsync(
string? query, string? query,
int take = 10, int take = 10,
int offset = 0, int offset = 0,
@@ -12,19 +12,18 @@ public class DiscoveryService(AppDatabase appDatabase)
) )
{ {
var realmsQuery = appDatabase.Realms var realmsQuery = appDatabase.Realms
.Take(take) .Where(r => r.IsCommunity)
.Skip(offset) .OrderByDescending(r => r.CreatedAt)
.Where(r => r.IsCommunity); .AsQueryable();
if (!string.IsNullOrEmpty(query)) if (!string.IsNullOrEmpty(query))
realmsQuery = realmsQuery.Where(r => realmsQuery = realmsQuery.Where(r =>
EF.Functions.ILike(r.Name, $"%{query}%") || EF.Functions.ILike(r.Name, $"%{query}%") ||
EF.Functions.ILike(r.Description, $"%{query}%") EF.Functions.ILike(r.Description, $"%{query}%")
); );
if (randomizer) realmsQuery = randomizer
realmsQuery = realmsQuery.OrderBy(r => EF.Functions.Random()); ? realmsQuery.OrderBy(r => EF.Functions.Random())
else : realmsQuery.OrderByDescending(r => r.CreatedAt);
realmsQuery = realmsQuery.OrderByDescending(r => r.CreatedAt);
return realmsQuery.Skip(offset).Take(take).ToListAsync(); return realmsQuery.Skip(offset).Take(take).ToListAsync();
} }