* fix: #1068

* add: ThemeSettingService.save add SERIALIZABLE level

* add: saveSettingsByThemeId Api add @CacheLock
pull/1072/head
王存露 2020-09-15 00:13:01 +08:00 committed by GitHub
parent 504e6e187e
commit ed46ab7031
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 7 additions and 1 deletions

View File

@ -5,6 +5,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import run.halo.app.annotation.DisableOnCondition; import run.halo.app.annotation.DisableOnCondition;
import run.halo.app.cache.lock.CacheLock;
import run.halo.app.handler.theme.config.support.Group; import run.halo.app.handler.theme.config.support.Group;
import run.halo.app.handler.theme.config.support.ThemeProperty; import run.halo.app.handler.theme.config.support.ThemeProperty;
import run.halo.app.model.params.ThemeContentParam; import run.halo.app.model.params.ThemeContentParam;
@ -144,6 +145,7 @@ public class ThemeController {
@PostMapping("{themeId}/settings") @PostMapping("{themeId}/settings")
@ApiOperation("Saves theme settings") @ApiOperation("Saves theme settings")
@CacheLock(prefix = "save_theme_setting_by_themeId")
public void saveSettingsBy(@PathVariable("themeId") String themeId, public void saveSettingsBy(@PathVariable("themeId") String themeId,
@RequestBody Map<String, Object> settings) { @RequestBody Map<String, Object> settings) {
themeSettingService.save(settings, themeId); themeSettingService.save(settings, themeId);

View File

@ -4,6 +4,7 @@ import freemarker.template.Configuration;
import freemarker.template.TemplateModelException; import freemarker.template.TemplateModelException;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Example;
import org.springframework.lang.NonNull; import org.springframework.lang.NonNull;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -87,7 +88,10 @@ public class ThemeSettingServiceImpl extends AbstractCrudService<ThemeSetting, I
log.debug("Creating theme setting: [{}]", setting); log.debug("Creating theme setting: [{}]", setting);
return setting; return setting;
}); });
// Determine whether the data already exists
if (themeSettingRepository.findOne(Example.of(themeSetting)).isPresent()) {
return null;
}
// Save the theme setting // Save the theme setting
return themeSettingRepository.save(themeSetting); return themeSettingRepository.save(themeSetting);
} }