1. add 网易云音乐解析

This commit is contained in:
QAIU
2024-10-20 18:16:51 +08:00
parent 0a3db51c7d
commit 10eec323dd
13 changed files with 83 additions and 38 deletions

View File

@@ -52,15 +52,16 @@ public class CacheManager {
}
// 写入网盘厂商API解析次数
public Future<Integer> updateTotalByCached(String shareKey) {
public Future<Integer> updateTotalByField(String shareKey, CacheTotalField field) {
Promise<Integer> promise = Promise.promise();
String fieldLower = field.name().toLowerCase();
String sql = """
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `cache_hit_total`, `update_ts`)
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `{field}`, `update_ts`)
KEY (`share_key`)
VALUES (#{panType}, #{shareKey}, #{total}, #{ts})
""";
""".replace("field", fieldLower);
getShareKeyTotal(shareKey, "cache_hit_total").onSuccess(total -> {
getShareKeyTotal(shareKey, fieldLower).onSuccess(total -> {
Integer newTotal = (total == null ? 0 : total) + 1;
SqlTemplate.forUpdate(jdbcPool, sql)
.execute(new HashMap<>() {{
@@ -81,30 +82,6 @@ public class CacheManager {
return fullShareKey.split(":")[0];
}
// 写入网盘厂商API解析次数
public Future<Integer> updateTotalByParser(String shareKey) {
Promise<Integer> promise = Promise.promise();
String sql = """
MERGE INTO `api_statistics_info` (`pan_type`, `share_key`, `api_parser_total`, `update_ts`)
KEY (`share_key`)
VALUES (#{panType}, #{shareKey}, #{total}, #{ts})
""";
getShareKeyTotal(shareKey, "api_parser_total").onSuccess(total -> {
Integer newTotal = (total == null ? 0 : total) + 1;
SqlTemplate.forUpdate(jdbcPool, sql)
.execute(new HashMap<>() {{
put("panType", getShareType(shareKey));
put("shareKey", shareKey);
put("total", newTotal);
put("ts", System.currentTimeMillis());
}})
.onSuccess(res -> promise.complete(res.rowCount()))
.onFailure(Throwable::printStackTrace);
});
return promise.future();
}
public Future<Integer> getShareKeyTotal(String shareKey, String name) {
String sql = """
select `share_key`, sum({total_name}) sum_num

View File

@@ -0,0 +1,10 @@
package cn.qaiu.lz.common.cache;
/**
* 缓存字段
*/
public enum CacheTotalField {
API_PARSER_TOTAL, // 解析次数
CACHE_HIT_TOTAL, // 缓存次数
FAILED_TOTAL // 解析失败次数
}

View File

@@ -3,6 +3,7 @@ package cn.qaiu.lz.web.service.impl;
import cn.qaiu.entity.ShareLinkInfo;
import cn.qaiu.lz.common.cache.CacheConfigLoader;
import cn.qaiu.lz.common.cache.CacheManager;
import cn.qaiu.lz.common.cache.CacheTotalField;
import cn.qaiu.lz.web.model.CacheLinkInfo;
import cn.qaiu.lz.web.service.CacheService;
import cn.qaiu.parser.ParserCreate;
@@ -46,12 +47,12 @@ public class CacheServiceImpl implements CacheService {
"shareKey", cacheKey
));
cacheManager.cacheShareLink(cacheLinkInfo).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByParser(cacheKey).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByField(cacheKey, CacheTotalField.API_PARSER_TOTAL).onFailure(Throwable::printStackTrace);
}).onFailure(promise::fail);
} else {
result.setExpires(generateDate(result.getExpiration()));
promise.complete(result);
cacheManager.updateTotalByCached(cacheKey).onFailure(Throwable::printStackTrace);
cacheManager.updateTotalByField(cacheKey, CacheTotalField.CACHE_HIT_TOTAL).onFailure(Throwable::printStackTrace);
}
}).onFailure(t -> promise.fail(t.fillInStackTrace()));
return promise.future();