mirror of https://github.com/halo-dev/halo
Fix option updated event bug
parent
7070c92b19
commit
d9dbc5ab13
|
@ -12,14 +12,11 @@ import org.springframework.stereotype.Component;
|
|||
import run.halo.app.event.options.OptionUpdatedEvent;
|
||||
import run.halo.app.event.theme.ThemeActivatedEvent;
|
||||
import run.halo.app.event.user.UserUpdatedEvent;
|
||||
import run.halo.app.handler.theme.config.support.ThemeProperty;
|
||||
import run.halo.app.service.OptionService;
|
||||
import run.halo.app.service.ThemeService;
|
||||
import run.halo.app.service.ThemeSettingService;
|
||||
import run.halo.app.service.UserService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Freemarker config aware listener.
|
||||
*
|
||||
|
|
|
@ -1,29 +0,0 @@
|
|||
package run.halo.app.event.options;
|
||||
|
||||
import org.springframework.context.ApplicationListener;
|
||||
import org.springframework.scheduling.annotation.Async;
|
||||
import org.springframework.stereotype.Component;
|
||||
import run.halo.app.cache.StringCacheStore;
|
||||
import run.halo.app.service.OptionService;
|
||||
|
||||
/**
|
||||
* Option updated listener.
|
||||
*
|
||||
* @author johnniang
|
||||
* @date 19-4-29
|
||||
*/
|
||||
@Component
|
||||
public class OptionUpdatedListener implements ApplicationListener<OptionUpdatedEvent> {
|
||||
|
||||
private final StringCacheStore cacheStore;
|
||||
|
||||
public OptionUpdatedListener(StringCacheStore cacheStore) {
|
||||
this.cacheStore = cacheStore;
|
||||
}
|
||||
|
||||
@Override
|
||||
@Async
|
||||
public void onApplicationEvent(OptionUpdatedEvent event) {
|
||||
cacheStore.delete(OptionService.OPTIONS_KEY);
|
||||
}
|
||||
}
|
|
@ -221,6 +221,11 @@ public abstract class AbstractCrudService<DOMAIN, ID> implements CrudService<DOM
|
|||
return repository.saveAndFlush(domain);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void flush() {
|
||||
repository.flush();
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates by domains
|
||||
*
|
||||
|
|
|
@ -148,6 +148,11 @@ public interface CrudService<DOMAIN, ID> {
|
|||
@Transactional
|
||||
DOMAIN update(@NonNull DOMAIN domain);
|
||||
|
||||
/**
|
||||
* Flushes all pending changes to the database.
|
||||
*/
|
||||
void flush();
|
||||
|
||||
/**
|
||||
* Updates by domains
|
||||
*
|
||||
|
|
|
@ -381,7 +381,13 @@ public class OptionServiceImpl extends AbstractCrudService<Option, Integer> impl
|
|||
});
|
||||
}
|
||||
|
||||
private void cleanCache() {
|
||||
cacheStore.delete(OptionService.OPTIONS_KEY);
|
||||
}
|
||||
|
||||
private void publishOptionUpdatedEvent() {
|
||||
cleanCache();
|
||||
eventPublisher.publishEvent(new OptionUpdatedEvent(this));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -331,6 +331,8 @@ public class ThemeServiceImpl implements ThemeService {
|
|||
// Set activated theme
|
||||
setActivatedTheme(themeProperty);
|
||||
|
||||
optionService.flush();
|
||||
|
||||
// Clear the cache
|
||||
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));
|
||||
|
||||
|
|
Loading…
Reference in New Issue