为AuthIdManager提供定期清理和线程安全特性#1
Open
SaladDay wants to merge 1 commit into
Open
Conversation
ZhuLegend
requested changes
Jun 11, 2024
| if time.time() - timestamp < self._ttl: | ||
| return uid | ||
| else: | ||
| del self._uids[sid] |
Collaborator
There was a problem hiding this comment.
这个类主要是提供了一个用户ID集中缓存的地方,资源清理是为了自动释放长时间未使用的uid节省内存,所以在一个uid被访问、检测到过期时,正确的行为应该是更新uid的过期时间而非删除uid返回None。前者是无意义的,且会导致一次额外的教务网访问,后者则可以正确清理不频繁访问的uid——频繁访问的uid会被不断更新时间戳而延后清理
| sh = sha3_256() | ||
| sh.update((auth + name + sid).encode('utf-8')) | ||
| result = sh.digest() | ||
| self._uids[sid] = (result,time.time()) |
Collaborator
There was a problem hiding this comment.
如果从节省内存的角度考虑,给每一项多存一个float值带来的内存增加是否会超过定时清理节省下来的内存?介于ttl一般是一个比较大的整数,在我们已经认为几百上千个string带来的内存占用应该被节省的情况下,将time.time()返回值直接转为整数是否更符合我们修改的预期?(这里不进行更改也可以通过review,改进了更好)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.