1.remove redundant code

main
Gary 9 months ago
parent 7a8aaeb634
commit 9fe9423b1d

@ -47,24 +47,7 @@ public class SaticScheduleTask {
@PostConstruct
private void init() {
Stream<Entry<String, Set<String>>> journalSongStream = journalSongDao.findAll().parallelStream()
.map(j -> getJournalSongMap(j)).flatMap(m -> m.entrySet().stream());
Stream<Entry<String, Set<String>>> journalStream = journalDao.findValidJournals().parallelStream()
.map(j -> getJournalMap(j)).flatMap(m -> m.entrySet().stream());
Map<String, List<Entry<String, Set<String>>>> map = Stream.concat(journalSongStream, journalStream)
.collect(Collectors.groupingBy(e -> e.getKey()));
int keyCount = map.size();
int cacheKeyCount = cacheChannel.keys(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE).size();
if (keyCount != cacheKeyCount) {
map.entrySet().forEach(e -> {
List<String> value = e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted()
.collect(Collectors.toList());
cacheChannel.set(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE, e.getKey(), value);
});
}
updateAutoComplete();
}
// 1.凌晨4点执行更新期刊tag
@ -92,7 +75,7 @@ public class SaticScheduleTask {
int keyCount = map.size();
int cacheKeyCount = cacheChannel.keys(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE).size();
if (keyCount != cacheKeyCount) {
map.entrySet().forEach(e -> {
map.entrySet().parallelStream().forEach(e -> {
List<String> value = e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted()
.collect(Collectors.toList());
cacheChannel.set(constants.Constants.J2CACHE_REGION_SEARCH_AUTO_COMPLETE, e.getKey(), value);

@ -4,4 +4,4 @@ journal_id: 2000, 6h
journal_no: 2000, 6h
journal_song_key: 10000, 6h
journal_song_list: 2000, 6h
search_auto_complete: 200000
search_auto_complete: 200000, 365d

@ -0,0 +1,42 @@
package com.luoo.music.config;
import static org.junit.Assert.*;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.junit.Test;
public class SaticScheduleTaskTest {
@Test
public void test() {
Map<String, Set<String>> map1=new HashMap<>();
map1.put("1", Arrays.asList("1","11").stream().collect(Collectors.toSet()));
map1.put("2", Arrays.asList("2","22").stream().collect(Collectors.toSet()));
Map<String, Set<String>> map2=new HashMap<>();
map2.put("1", Arrays.asList("2_1","2_11").stream().collect(Collectors.toSet()));
map2.put("2", Arrays.asList("2_2","2_22").stream().collect(Collectors.toSet()));
Stream<Entry<String, Set<String>>> journalSongStream = map1.entrySet().stream();
Stream<Entry<String, Set<String>>> journalStream = map2.entrySet().stream();
Map<String, List<Entry<String, Set<String>>>> map = Stream.concat(journalSongStream, journalStream)
.collect(Collectors.groupingBy(e -> e.getKey()));
map.entrySet().forEach(e -> {
List<String> value = e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted()
.collect(Collectors.toList());
System.out.println(value.stream().collect(Collectors.joining(",")));
});
}
}
Loading…
Cancel
Save