Fix option updated event bug

pull/146/head
johnniang 2019-05-08 16:48:24 +08:00
parent 7070c92b19
commit d9dbc5ab13
6 changed files with 18 additions and 32 deletions

View File

@ -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.
*

View File

@ -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);
}
}

View File

@ -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
*

View File

@ -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
*

View File

@ -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));
}
}

View File

@ -331,6 +331,8 @@ public class ThemeServiceImpl implements ThemeService {
// Set activated theme
setActivatedTheme(themeProperty);
optionService.flush();
// Clear the cache
eventPublisher.publishEvent(new ThemeUpdatedEvent(this));