From f1920c54f00b6f685469b3fa4327b5f7f961d446 Mon Sep 17 00:00:00 2001 From: "zhouxin5253@163.com" <9a@2gvp!hs3> Date: Tue, 19 Jan 2021 12:20:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E7=BC=93=E5=AD=98=E7=AD=96?= =?UTF-8?q?=E7=95=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../store/TeambitionClientService.java | 40 ++++++++++++------- .../store/TeambitionFileSystemStore.java | 2 + 2 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java index bf0ecd8..ae9830e 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java +++ b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionClientService.java @@ -27,8 +27,7 @@ public class TeambitionClientService { private static String rootPath = "/"; private static int chunkSize = 10485760; // 10MB private TFile rootTFile = null; - private Map nodeIdMap = new ConcurrentHashMap<>(); - private Map> tFilesCache = new ConcurrentHashMap<>(); + private ThreadLocal>> tFilesCache = new ThreadLocal<>(); private final TeambitionClient client; @@ -38,7 +37,12 @@ public class TeambitionClientService { } public Set getTFiles(String nodeId) { - return tFilesCache.computeIfAbsent(nodeId, key -> { + Map> map = tFilesCache.get(); + if (map == null) { + map = new ConcurrentHashMap<>(); + tFilesCache.set(map); + } + return map.computeIfAbsent(nodeId, key -> { NodeQuery nodeQuery = new NodeQuery(); nodeQuery.setOrgId(client.getOrgId()); nodeQuery.setOffset(0); @@ -145,6 +149,11 @@ public class TeambitionClientService { if (oldFile != null) { LOGGER.info("旧文件{}还存在,大小为{},进行删除操作,可前往网页版的回收站查看", path, oldFile.getSize()); remove(path); + try { + Thread.sleep(1500); + } catch (InterruptedException e) { + // no + } } RenameRequest renameRequest = new RenameRequest(); renameRequest.setCcpFileId(uploadPreResult.getCcpFileId()); @@ -153,7 +162,7 @@ public class TeambitionClientService { renameRequest.setName(pathInfo.getName()); client.put("/pan/api/nodes/" + parent.getNodeId(), renameRequest); } - clearCache(path); + clearCache(); } public void rename(String sourcePath, String newName) { @@ -165,7 +174,7 @@ public class TeambitionClientService { renameRequest.setOrgId(client.getOrgId()); renameRequest.setName(newName); client.put("/pan/api/nodes/" + tFile.getParentId(), renameRequest); - clearCache(sourcePath); + clearCache(); } public void move(String sourcePath, String targetPath) { @@ -183,8 +192,8 @@ public class TeambitionClientService { moveRequestId.setId(sourceTFile.getNodeId()); moveRequest.setIds(Collections.singletonList(moveRequestId)); client.post("/pan/api/nodes/move", moveRequest); - clearCache(sourcePath); - clearCache(targetPath); + clearCache(); + clearCache(); } public void remove(String path) { @@ -197,7 +206,7 @@ public class TeambitionClientService { removeRequest.setOrgId(client.getOrgId()); removeRequest.setNodeIds(Collections.singletonList(tFile.getNodeId())); client.post("/pan/api/nodes/archive", removeRequest); - clearCache(path); + clearCache(); } @@ -228,16 +237,16 @@ public class TeambitionClientService { if (!createFileResult.getName().equals(pathInfo.getName())) { LOGGER.info("创建目录{}与原值{}不同,重命名", createFileResult.getName(), pathInfo.getName()); rename(pathInfo.getParentPath() + "/" + createFileResult.getName(), pathInfo.getName()); - clearCache(pathInfo.getParentPath() + "/" + createFileResult.getName()); + clearCache(); } - clearCache(path); + clearCache(); } public TFile getTFileByPath(String path) { path = normalizingPath(path); - return nodeIdMap.computeIfAbsent(path, this::getNodeIdByPath2); + return getNodeIdByPath2(path); } public InputStream download(String path) { @@ -311,8 +320,11 @@ public class TeambitionClientService { return path; } - private void clearCache(String path) { - nodeIdMap.remove(path); - tFilesCache.clear(); + public void clearCache() { + Map> map = tFilesCache.get(); + if (map != null) { + map.clear(); + } + } } diff --git a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java index 930e408..6a0d4e5 100644 --- a/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java +++ b/src/main/java/com/github/zxbu/webdavteambition/store/TeambitionFileSystemStore.java @@ -40,6 +40,7 @@ public class TeambitionFileSystemStore implements IWebdavStore { @Override public ITransaction begin(Principal principal) { LOGGER.debug("begin"); + teambitionClientService.clearCache(); return null; } @@ -51,6 +52,7 @@ public class TeambitionFileSystemStore implements IWebdavStore { @Override public void commit(ITransaction transaction) { + teambitionClientService.clearCache(); LOGGER.debug("commit"); }