Skip to content

Commit

Permalink
More performant random quote fetching
Browse files Browse the repository at this point in the history
  • Loading branch information
Atulin committed Jul 6, 2024
1 parent 3fcdcdc commit 436b28f
Show file tree
Hide file tree
Showing 5 changed files with 2,289 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Ogma3/Api/V1/Quotes/Queries/GetRandom.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public async ValueTask<ActionResult<QuoteDto>> Handle(Query request, Cancellatio
var quote = await context.Database.SqlQueryRaw<QuoteDto>("""
SELECT q."Author", q."Body"
FROM "Quotes" q
TABLESAMPLE bernoulli(.5)
TABLESAMPLE SYSTEM_ROWS(1)
LIMIT 1
""")
.FirstOrDefaultAsync(cancellationToken);
Expand Down
4 changes: 3 additions & 1 deletion Ogma3/Data/ApplicationDbContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,9 @@ protected override void OnModelCreating(ModelBuilder builder)
base.OnModelCreating(builder);

// Extensions
builder.HasPostgresExtension("uuid-ossp");
builder
.HasPostgresExtension("uuid-ossp")
.HasPostgresExtension("tsm_system_rows");

// Register all enums with `[PostgresEnum]` attribute
builder.RegisterPostgresEnums();
Expand Down
Loading

0 comments on commit 436b28f

Please sign in to comment.