Added caching to UserController pfp endpoint
This commit is contained in:
parent
38f02d0b7c
commit
39d7a0f15a
|
@ -1,6 +1,6 @@
|
|||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.OutputCaching;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Wave.Data;
|
||||
using Wave.Services;
|
||||
|
@ -8,13 +8,15 @@
|
|||
namespace Wave.Controllers;
|
||||
|
||||
[ApiController]
|
||||
[Microsoft.AspNetCore.Mvc.Route("/api/[controller]")]
|
||||
[Route("/api/[controller]")]
|
||||
public class UserController(ImageService imageService, IDbContextFactory<ApplicationDbContext> contextFactory) : ControllerBase {
|
||||
private ImageService ImageService { get; } = imageService;
|
||||
private IDbContextFactory<ApplicationDbContext> ContextFactory { get; } = contextFactory;
|
||||
|
||||
[HttpGet]
|
||||
[Microsoft.AspNetCore.Mvc.Route("pfp/{userId}")]
|
||||
[OutputCache(Duration = 60*5)]
|
||||
[ResponseCache(Duration = 60*5, Location = ResponseCacheLocation.Any)]
|
||||
[Route("pfp/{userId}")]
|
||||
public async Task<IActionResult> Get(string userId) {
|
||||
await using var context = await ContextFactory.CreateDbContextAsync();
|
||||
var user = await context.Users.Include(u => u.ProfilePicture).FirstOrDefaultAsync(u => u.Id == userId);
|
||||
|
|
Loading…
Reference in a new issue