mysql 可以用 select length("中国") 计算varchar 长度。
eleme ui el-select 远程模糊搜索例子
Vue.component('MySuperGame', {
props: {
// 双向绑定值
value: {
type: [String, Number, Array],
default: ''
},
platform: {
type: [String, Number],
default: 0
},
// 初始默认值(用于回显)
initialValue: {
type: [String, Number, Array],
default: ''
},
// 是否多选
multiple: {
type: Boolean,
default: false
},
// 防抖时间(毫秒)
debounceTime: {
type: Number,
default: 300
},
// 是否启用缓存
enableCache: {
type: Boolean,
default: true
},
// 自定义结果格式化函数
formatter: {
type: Function,
default: items => items.map(item => ({
value: item.id+'',
label: item.id+'-'+item.title+'-' + item.subtitle,
gameInfo: item
}))
}
},
data() {
return {
localValue: this.value || this.initialValue,
options: [],
loading: false,
searchKeyword: '',
searchCache: new Map(),
cancelToken: null
}
},
watch: {
'platform': {
handler(newVal, oldVal) {
if (newVal > 0 && newVal != oldVal) {
this.localValue = ''; // 清空绑定值
this.options = []; // 清空绑定值
}
},
},
value(newVal) {
this.localValue = newVal
},
localValue(newVal) {
this.$emit('input', newVal)
this.$emit('change', newVal)
let gameNode=this.options.filter(item => {
if(item.value==newVal){
return true
}
})
if(gameNode[0]){
this.$emit('gamechange', gameNode[0].gameInfo)
}
}
},
created() {
console.log('platform',this.platform)
// 初始化加载默认值对应的选项
if (this.localValue) {
this.loadInitialValues()
}
},
methods: {
// 防抖搜索方法
handleSearch: _.debounce( async function (keyword) {
this.searchKeyword = keyword.trim()
if (!this.searchKeyword) {
this.options = []
return
}
this.loading = true
this.cancelPreviousRequest()
let response = await axios.post('/topic/card/getGameNodeSearch', {key: keyword, platform: this.platform,format:0})
.catch(error => {
if (!axios.isCancel(error)) {
console.error('Remote search failed:', error)
this.$message.error('搜索失败,请稍后重试')
}
})
.finally(() => (this.loading = false))
const items = this.formatter(response.data.data.gameList || [])
if (this.enableCache) {
this.searchCache.set(this.searchKeyword, items)
}
this.options = items
}, 300),
// 取消之前的请求
cancelPreviousRequest() {
if (this.cancelToken) {
this.cancelToken('取消重复请求')
}
},
// 加载初始值对应的选项
async loadInitialValues() {
try {
this.loading = true
const id = this.localValue
const response = await axios.post(`/topic/card/getGameNodeSearch`, {key: id, format: 0, platform: this.platform})
this.options = this.formatter(response.data.data.gameList || [])
} catch (error) {
console.error('初始化加载失败:', error)
} finally {
this.loading = false
}
},
// 高亮匹配文本
highlight(label) {
if (!this.searchKeyword) return label
const regex = new RegExp(`(${this.searchKeyword})`, 'gi')
return label.replace(regex, '<span class="highlight">$1</span>')
}
},
template: `
<el-select
v-model="localValue"
filterable
clearable
remote
reserve-keyword
placeholder="请输入游戏名或游戏ID"
:multiple="multiple"
:remote-method="handleSearch"
:loading="loading"
:loading-text="'加载中...'"
:no-match-text="'无匹配结果'"
:no-data-text="'暂无数据'"
>
<el-option
v-for="item in options"
:key="item.value"
:label="item.label"
:value="item.value"
>
<span v-html="highlight(item.label)"></span>
</el-option>
</el-select>
`
})
k8s 利用 HPA自动缩容
# 定义 Deployment
apiVersion: apps/v1
kind: Deployment
metadata:
name: nginx-deployment
labels:
app: nginx
spec:
#replicas: 2 # 指定 3 个副本
selector:
matchLabels:
app: nginx
template:
metadata:
labels:
app: nginx
spec:
containers:
- name: nginx
image: nginx:1.25.3 # 使用官方稳定版本
ports:
- containerPort: 80 # 容器监听的端口
resources:
requests:
memory: "64Mi"
cpu: "250m"
limits:
memory: "128Mi"
cpu: "500m"
# 健康检查(可选)
livenessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 5
periodSeconds: 10
readinessProbe:
httpGet:
path: /
port: 80
initialDelaySeconds: 2
periodSeconds: 5
---
---
# 定义 Service
apiVersion: v1
kind: Service
metadata:
name: nginx-service
spec:
type: NodePort # 通过节点端口暴露服务
selector:
app: nginx # 必须与 Deployment 的标签匹配
ports:
- protocol: TCP
port: 80 # Service 的端口
targetPort: 80 # 容器的端口
nodePort: 30080 # 节点的端口(范围 30000-32767)
---
# nginx-hpa.yaml
apiVersion: autoscaling/v2
kind: HorizontalPodAutoscaler
metadata:
name: nginx-hpa
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: nginx-deployment
minReplicas: 2
maxReplicas: 10
metrics:
- type: Resource
resource:
name: cpu
target:
type: Utilization
averageUtilization: 10 # 目标 CPU 使用率 50%
# - type: Pods
# pods:
# metric:
# name: requests-per-second
# target:
# type: AverageValue
# averageValue: 20
behavior:
scaleDown:
stabilizationWindowSeconds: 20
selectPolicy: Max
policies:
- type: Percent
value: 50
periodSeconds: 10
scaleUp:
stabilizationWindowSeconds: 20
selectPolicy: Max
policies:
- type: Percent
value: 50
periodSeconds: 10
Deployment
apiVersion: apps/v1:指定 API 版本。
kind: Deployment:指定资源类型为 Deployment。
metadata:元数据部分。
name: nginx-deployment:Deployment 的名称。
labels:标签,用于标识 Deployment。
app: nginx:标签键值对,键为 app,值为 nginx。
spec:规范部分。
replicas: 1:指定副本数为 1。
selector:选择器,用于选择要管理的 Pods。
matchLabels:匹配标签。
app: nginx:匹配标签键值对,键为 app,值为 nginx。
template:Pod 模板。
metadata:Pod 的元数据。
labels:Pod 的标签。
app: nginx:标签键值对,键为 app,值为 nginx。
spec:Pod 的规范。
containers:容器列表。
name: nginx:容器名称。
image: nginx:1.25.3:使用的镜像。
ports:端口列表。
containerPort: 80:容器监听的端口。
resources:资源请求和限制。
requests:资源请求。
memory: "64Mi":请求的内存。
cpu: "250m":请求的 CPU。
limits:资源限制。
memory: "128Mi":限制的内存。
cpu: "500m":限制的 CPU。
livenessProbe:存活性探针。
httpGet:HTTP GET 请求。
path: /:请求路径。
port: 80:请求端口。
initialDelaySeconds: 5:初始延迟。
periodSeconds: 10:检查间隔。
readinessProbe:就绪性探针。
httpGet:HTTP GET 请求。
path: /:请求路径。
port: 80:请求端口。
initialDelaySeconds: 2:初始延迟。
periodSeconds: 5:检查间隔。
Service
apiVersion: v1:指定 API 版本。
kind: Service:指定资源类型为 Service。
metadata:元数据部分。
name: nginx-service:Service 的名称。
spec:规范部分。
type: NodePort:通过节点端口暴露服务。
selector:选择器,用于选择要暴露的 Pods。
app: nginx:选择标签键值对,键为 app,值为 nginx。
ports:端口列表。
protocol: TCP:协议类型。
port: 80:Service 的端口。
targetPort: 80:容器的端口。
nodePort: 30080:节点的端口(范围 30000-32767)。
Horizontal Pod Autoscaler (HPA)
apiVersion: autoscaling/v2:指定 API 版本。
kind: HorizontalPodAutoscaler:指定资源类型为 HPA。
metadata:元数据部分。
name: nginx-hpa:HPA 的名称。
spec:规范部分。
scaleTargetRef:扩展目标引用。
apiVersion: apps/v1:目标 API 版本。
kind: Deployment:目标资源类型。
name: nginx-deployment:目标 Deployment 的名称。
minReplicas: 2:最小副本数。
maxReplicas: 10:最大副本数。
metrics:指标列表。
type: Resource:资源类型指标。
resource:资源名称。
name: cpu:CPU 资源。
target:目标设置。
type: Utilization:使用率类型。
averageUtilization: 50:目标 CPU 使用率为 50%。
type: Pods:Pods 类型指标。
pods:Pods 指标。
metric:指标名称。
name: requests-per-second:每秒请求数。
target:目标设置。
type: AverageValue:平均值类型。
averageValue: 20:目标每秒平均请求数为 20。
behavior:行为设置。
scaleDown:缩减设置。
stabilizationWindowSeconds: 300:稳定窗口时间(秒)。
selectPolicy: Max:选择策略为最大值。
policies:策略列表。
type: Percent:百分比类型。
value: 50:缩减百分比为 50%。
periodSeconds: 60:策略周期(秒)。
scaleUp:扩展设置。
stabilizationWindowSeconds: 600:稳定窗口时间(秒)。
selectPolicy: Max:选择策略为最大值。
policies:策略列表。
type: Percent:百分比类型。
value: 100:扩展百分比为 100%。
periodSeconds: 60:策略周期(秒)。
MicroK8s 搭建步骤
deban系统安装MicroK8s
apt update && sudo apt upgrade -y
apt install snapd
snap install core
unbantu
sudo snap install microk8s --classic
sudo snap alias microk8s.kubectl kubectl
sudo snap alias microk8s.ctr ctr
sudo snap alias microk8s.helm helm
sudo snap alias microk8s.helm3 helm3
关于mysql FIND_IN_SET 的性能
caiji_soft 5000条数据
select id FROM caiji_soft where FIND_IN_SET(21,tag) or FIND_IN_SET(32,tag)
OK
时间: 0.021s