Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

开启异步count支持后,不兼容Mybatis-Plus的多租户插件 #805

Open
java-my-life opened this issue Feb 18, 2024 · 4 comments
Open

Comments

@java-my-life
Copy link

使用环境

  • PageHelper 版本: 2.0.0
  • MybatisPlus版本: 3.5.5

配置多租户插件

interceptor.addInnerInterceptor(new TenantLineInnerInterceptor(new TenantLineHandler() {
        @Override
        public Expression getTenantId() {
          return new StringValue(ContextHolder.getTenant());
        }
        @Override
        public boolean ignoreTable(String tableName) {
          return false;
        }
      }));

开启异步count支持后

发现count条件中并没有tenant_id
image

关闭异步count支持后

一切正常,count条件中存在tenant_id
image

@cqu2014
Copy link

cqu2014 commented Feb 18, 2024 via email

@abel533
Copy link
Collaborator

abel533 commented Feb 19, 2024

考虑增加一个简单接口允许处理上下文。。在进入异步线程前执行a()方法,进入异步线程执行后执行b()方法。

a()方法可以先从ThreadLocal取值,b()方法可以存值。。执行完成后执行c()方法清理ThreadLocal,你看看是否可行?

@java-my-life
Copy link
Author

意思是要手动把条件塞进去吗?
这样count是可以,但是正常的列表查询就会出现两条相同的条件。
目前开启异步count的话,是不是所有的实现mybatisPlus的InnerInterceptor拦截器都存在问题?
之后版本会修复这个问题吗?

@pagehelper
Copy link
Owner

首先这不算问题,主要是ThreadLocal线程绑定的原因,如果在mybatis中遇到类似拦截器,都需要手动在新线程上进行绑定。

你这种情况就别用异步count了。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants