forked from Fascinated/Bat
fix guild and user caching
This commit is contained in:
parent
61d96191cb
commit
47beff752c
@ -11,10 +11,8 @@ import lombok.extern.log4j.Log4j2;
|
|||||||
import net.dv8tion.jda.api.JDA;
|
import net.dv8tion.jda.api.JDA;
|
||||||
import net.dv8tion.jda.api.Permission;
|
import net.dv8tion.jda.api.Permission;
|
||||||
import net.dv8tion.jda.api.entities.Guild;
|
import net.dv8tion.jda.api.entities.Guild;
|
||||||
import net.dv8tion.jda.api.entities.channel.concrete.PrivateChannel;
|
|
||||||
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
import net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.internal.entities.channel.concrete.PrivateChannelImpl;
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
|
@ -7,6 +7,8 @@ import lombok.extern.log4j.Log4j2;
|
|||||||
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
import net.dv8tion.jda.api.events.guild.GuildJoinEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CachePut;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -35,6 +37,7 @@ public class GuildService extends ListenerAdapter {
|
|||||||
* @param id The ID of the guild
|
* @param id The ID of the guild
|
||||||
* @return The guild
|
* @return The guild
|
||||||
*/
|
*/
|
||||||
|
@Cacheable(cacheNames = {"guilds"}, key = "#id")
|
||||||
public BatGuild getGuild(@NonNull String id) {
|
public BatGuild getGuild(@NonNull String id) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Optional<BatGuild> optionalGuild = guildRepository.findById(id);
|
Optional<BatGuild> optionalGuild = guildRepository.findById(id);
|
||||||
@ -51,6 +54,7 @@ public class GuildService extends ListenerAdapter {
|
|||||||
*
|
*
|
||||||
* @param guild The guild to save
|
* @param guild The guild to save
|
||||||
*/
|
*/
|
||||||
|
@CachePut(cacheNames = {"guilds"}, key = "#id")
|
||||||
public void saveGuild(@NonNull BatGuild guild) {
|
public void saveGuild(@NonNull BatGuild guild) {
|
||||||
guildRepository.save(guild);
|
guildRepository.save(guild);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ import cc.fascinated.bat.repository.UserRepository;
|
|||||||
import lombok.NonNull;
|
import lombok.NonNull;
|
||||||
import lombok.extern.log4j.Log4j2;
|
import lombok.extern.log4j.Log4j2;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.cache.annotation.CachePut;
|
||||||
|
import org.springframework.cache.annotation.Cacheable;
|
||||||
import org.springframework.context.annotation.DependsOn;
|
import org.springframework.context.annotation.DependsOn;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
@ -32,6 +34,7 @@ public class UserService {
|
|||||||
* @param id The ID of the user
|
* @param id The ID of the user
|
||||||
* @return The user
|
* @return The user
|
||||||
*/
|
*/
|
||||||
|
@Cacheable(cacheNames = {"users"}, key = "#id")
|
||||||
public BatUser getUser(@NonNull String id) {
|
public BatUser getUser(@NonNull String id) {
|
||||||
long start = System.currentTimeMillis();
|
long start = System.currentTimeMillis();
|
||||||
Optional<BatUser> optionalUser = userRepository.findById(id);
|
Optional<BatUser> optionalUser = userRepository.findById(id);
|
||||||
@ -48,6 +51,7 @@ public class UserService {
|
|||||||
*
|
*
|
||||||
* @param user The user to save
|
* @param user The user to save
|
||||||
*/
|
*/
|
||||||
|
@CachePut(cacheNames = {"users"}, key = "#id")
|
||||||
public void saveUser(@NonNull BatUser user) {
|
public void saveUser(@NonNull BatUser user) {
|
||||||
userRepository.save(user);
|
userRepository.save(user);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user