mirror of
https://github.com/LamGC/ContentGrabbingJi.git
synced 2025-04-30 06:37:36 +00:00
尝试使用Integer代替String以减少内存占用;
调整输出等级
This commit is contained in:
parent
078ab1caf0
commit
ad6e0b1c34
@ -90,7 +90,7 @@ public class CQPluginMain extends CQPlugin {
|
|||||||
String[] args = new String[argsList.size()];
|
String[] args = new String[argsList.size()];
|
||||||
argsList.toArray(args);
|
argsList.toArray(args);
|
||||||
|
|
||||||
log.info("正在处理命令...");
|
log.warn("正在处理命令...");
|
||||||
long time = System.currentTimeMillis();
|
long time = System.currentTimeMillis();
|
||||||
Object result;
|
Object result;
|
||||||
try {
|
try {
|
||||||
@ -113,7 +113,7 @@ public class CQPluginMain extends CQPlugin {
|
|||||||
log.error("执行命令时发生异常", e);
|
log.error("执行命令时发生异常", e);
|
||||||
result = "命令执行时发生错误,无法完成!";
|
result = "命令执行时发生错误,无法完成!";
|
||||||
}
|
}
|
||||||
log.info("命令处理完成(耗时: {}ms)", System.currentTimeMillis() - time);
|
log.warn("命令处理完成(耗时: {}ms)", System.currentTimeMillis() - time);
|
||||||
if(Objects.requireNonNull(result) instanceof String) {
|
if(Objects.requireNonNull(result) instanceof String) {
|
||||||
sendMessage(cq, event, (String) result, false);
|
sendMessage(cq, event, (String) result, false);
|
||||||
}
|
}
|
||||||
|
@ -44,11 +44,11 @@ public class CQProcess {
|
|||||||
|
|
||||||
private final static Hashtable<Integer, CacheObject<JsonObject>> illustPreLoadDataCache = new Hashtable<>();
|
private final static Hashtable<Integer, CacheObject<JsonObject>> illustPreLoadDataCache = new Hashtable<>();
|
||||||
|
|
||||||
private final static Hashtable<String, CacheObject<JsonObject>> searchBodyCache = new Hashtable<>();
|
private final static Hashtable<Integer, CacheObject<JsonObject>> searchBodyCache = new Hashtable<>();
|
||||||
|
|
||||||
private final static Hashtable<String, List<String>> pagesCache = new Hashtable<>();
|
private final static Hashtable<Integer, List<String>> pagesCache = new Hashtable<>();
|
||||||
|
|
||||||
private final static Hashtable<String, JsonArray> rankingCache = new Hashtable<>();
|
private final static Hashtable<Integer, JsonArray> rankingCache = new Hashtable<>();
|
||||||
|
|
||||||
private final static Object searchCacheLock = new Object();
|
private final static Object searchCacheLock = new Object();
|
||||||
|
|
||||||
@ -194,9 +194,10 @@ public class CQProcess {
|
|||||||
log.info("RequestUrl: {}", requestUrl);
|
log.info("RequestUrl: {}", requestUrl);
|
||||||
|
|
||||||
CacheObject<JsonObject> cacheObject = new CacheObject<>();
|
CacheObject<JsonObject> cacheObject = new CacheObject<>();
|
||||||
if(!searchBodyCache.containsKey(requestUrl) || (cacheObject = searchBodyCache.get(requestUrl)).isExpire(new Date())) {
|
int requestUrlSign = requestUrl.hashCode();
|
||||||
|
if(!searchBodyCache.containsKey(requestUrlSign) || (cacheObject = searchBodyCache.get(requestUrlSign)).isExpire(new Date())) {
|
||||||
synchronized (searchCacheLock) {
|
synchronized (searchCacheLock) {
|
||||||
if (!searchBodyCache.containsKey(requestUrl) || (cacheObject = searchBodyCache.get(requestUrl)).isExpire(new Date())) {
|
if (!searchBodyCache.containsKey(requestUrlSign) || (cacheObject = searchBodyCache.get(requestUrlSign)).isExpire(new Date())) {
|
||||||
log.info("searchBody缓存失效, 正在更新...");
|
log.info("searchBody缓存失效, 正在更新...");
|
||||||
JsonObject jsonObject;
|
JsonObject jsonObject;
|
||||||
HttpGet httpGetRequest = pixivDownload.createHttpGetRequest(requestUrl);
|
HttpGet httpGetRequest = pixivDownload.createHttpGetRequest(requestUrl);
|
||||||
@ -222,7 +223,7 @@ public class CQProcess {
|
|||||||
|
|
||||||
newExpireDate.setTime(newExpireDate.getTime() + expire);
|
newExpireDate.setTime(newExpireDate.getTime() + expire);
|
||||||
cacheObject.update(jsonObject, newExpireDate);
|
cacheObject.update(jsonObject, newExpireDate);
|
||||||
searchBodyCache.put(requestUrl, cacheObject);
|
searchBodyCache.put(requestUrlSign, cacheObject);
|
||||||
log.info("searchBody缓存已更新(到期时间: {})", newExpireDate);
|
log.info("searchBody缓存已更新(到期时间: {})", newExpireDate);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -230,7 +231,8 @@ public class CQProcess {
|
|||||||
log.info("搜索缓存命中.");
|
log.info("搜索缓存命中.");
|
||||||
}
|
}
|
||||||
|
|
||||||
JsonObject resultBody = searchBodyCache.get(requestUrl).get().getAsJsonObject("body");
|
JsonObject resultBody = searchBodyCache.get(requestUrlSign).get().getAsJsonObject("body");
|
||||||
|
|
||||||
StringBuilder result = new StringBuilder("内容 " + content + " 的搜索结果:\n");
|
StringBuilder result = new StringBuilder("内容 " + content + " 的搜索结果:\n");
|
||||||
log.info("正在处理信息...");
|
log.info("正在处理信息...");
|
||||||
int limit = 8;
|
int limit = 8;
|
||||||
@ -521,9 +523,10 @@ public class CQProcess {
|
|||||||
|
|
||||||
private final static Object illustPagesLock = new Object();
|
private final static Object illustPagesLock = new Object();
|
||||||
public static List<String> getIllustPages(int illustId, PixivDownload.PageQuality quality) throws IOException {
|
public static List<String> getIllustPages(int illustId, PixivDownload.PageQuality quality) throws IOException {
|
||||||
if (!pagesCache.containsKey(illustId + "." + quality.name())) {
|
int pagesSign = (illustId + "." + quality.name()).hashCode();
|
||||||
|
if (!pagesCache.containsKey(pagesSign)) {
|
||||||
synchronized (illustPagesLock) {
|
synchronized (illustPagesLock) {
|
||||||
if (!pagesCache.containsKey(illustId + "." + quality.name())) {
|
if (!pagesCache.containsKey(pagesSign)) {
|
||||||
File cacheFile = new File(getImageStoreDir(), illustId + "." + quality.name() + ".illustPages.json");
|
File cacheFile = new File(getImageStoreDir(), illustId + "." + quality.name() + ".illustPages.json");
|
||||||
log.info("illustPagesFileName: {}", cacheFile.getName());
|
log.info("illustPagesFileName: {}", cacheFile.getName());
|
||||||
List<String> linkList;
|
List<String> linkList;
|
||||||
@ -543,12 +546,12 @@ public class CQProcess {
|
|||||||
linkList = new ArrayList<>(jsonArray.size());
|
linkList = new ArrayList<>(jsonArray.size());
|
||||||
jsonArray.forEach(jsonElement -> linkList.add(jsonElement.getAsString()));
|
jsonArray.forEach(jsonElement -> linkList.add(jsonElement.getAsString()));
|
||||||
}
|
}
|
||||||
pagesCache.put(illustId + "." + quality.name(), linkList);
|
pagesCache.put(pagesSign, linkList);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return pagesCache.get(illustId + "." + quality.name());
|
return pagesCache.get(pagesSign);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static File getImageStoreDir() {
|
private static File getImageStoreDir() {
|
||||||
@ -562,7 +565,7 @@ public class CQProcess {
|
|||||||
private final static Object rankingLock = new Object();
|
private final static Object rankingLock = new Object();
|
||||||
private static List<JsonObject> getRankingInfoByCache(PixivURL.RankingContentType contentType, PixivURL.RankingMode mode, Date queryDate, int start, int range) throws IOException {
|
private static List<JsonObject> getRankingInfoByCache(PixivURL.RankingContentType contentType, PixivURL.RankingMode mode, Date queryDate, int start, int range) throws IOException {
|
||||||
String date = new SimpleDateFormat("yyyyMMdd").format(queryDate);
|
String date = new SimpleDateFormat("yyyyMMdd").format(queryDate);
|
||||||
String requestSign = "Ranking." + contentType.name() + "." + mode.name() + "." + date;
|
int requestSign = ("Ranking." + contentType.name() + "." + mode.name() + "." + date).hashCode();
|
||||||
if(!rankingCache.containsKey(requestSign)) {
|
if(!rankingCache.containsKey(requestSign)) {
|
||||||
synchronized(rankingLock) {
|
synchronized(rankingLock) {
|
||||||
if(!rankingCache.containsKey(requestSign)) {
|
if(!rankingCache.containsKey(requestSign)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user