From 9fe9423b1d68c8d0b05d9319cac71a2a78274a97 Mon Sep 17 00:00:00 2001 From: Gary Date: Tue, 5 Mar 2024 18:31:43 +0800 Subject: [PATCH] 1.remove redundant code --- .../luoo/music/config/SaticScheduleTask.java | 21 +--------- .../src/main/resources/caffeine.properties | 2 +- .../music/config/SaticScheduleTaskTest.java | 42 +++++++++++++++++++ 3 files changed, 45 insertions(+), 20 deletions(-) create mode 100644 luoo_music/src/test/java/com/luoo/music/config/SaticScheduleTaskTest.java diff --git a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java index f22a632..618b0c1 100644 --- a/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java +++ b/luoo_music/src/main/java/com/luoo/music/config/SaticScheduleTask.java @@ -47,24 +47,7 @@ public class SaticScheduleTask { @PostConstruct private void init() { - Stream>> journalSongStream = journalSongDao.findAll().parallelStream() - .map(j -> getJournalSongMap(j)).flatMap(m -> m.entrySet().stream()); - - Stream>> journalStream = journalDao.findValidJournals().parallelStream() - .map(j -> getJournalMap(j)).flatMap(m -> m.entrySet().stream()); - - Map>>> 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 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 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); diff --git a/luoo_music/src/main/resources/caffeine.properties b/luoo_music/src/main/resources/caffeine.properties index 3549a58..f4c641d 100644 --- a/luoo_music/src/main/resources/caffeine.properties +++ b/luoo_music/src/main/resources/caffeine.properties @@ -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 \ No newline at end of file +search_auto_complete: 200000, 365d \ No newline at end of file diff --git a/luoo_music/src/test/java/com/luoo/music/config/SaticScheduleTaskTest.java b/luoo_music/src/test/java/com/luoo/music/config/SaticScheduleTaskTest.java new file mode 100644 index 0000000..7a407b7 --- /dev/null +++ b/luoo_music/src/test/java/com/luoo/music/config/SaticScheduleTaskTest.java @@ -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> 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> 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>> journalSongStream = map1.entrySet().stream(); + + Stream>> journalStream = map2.entrySet().stream(); + + Map>>> map = Stream.concat(journalSongStream, journalStream) + .collect(Collectors.groupingBy(e -> e.getKey())); + + map.entrySet().forEach(e -> { + List value = e.getValue().stream().flatMap(a -> a.getValue().stream()).distinct().sorted() + .collect(Collectors.toList()); + System.out.println(value.stream().collect(Collectors.joining(","))); + }); + } + +}