当前位置:网站首页>抖音实战~取关博主
抖音实战~取关博主
2022-06-28 03:40:00 【gblfy】


文章目录
一、需求分析
1. 取关流程图

2. 取关流程简述
- 1.前端携带用户ID和短视频发布者ID请求后端取关接口
- 2.判断我们是否朋友关系
- 2.1.非朋友关系,删除自己的关注关联表记录
- 2.2.朋友关系,抹除双方的朋友关系,设置非朋友状态,更新数据库
- 3.我关注总量-1(redis)
- 4.博主粉丝量-1(redis)
- 5.删除我和短视频博主的关系(redis)
二、源码实战
2.1. 取关~前端
// 取消关注
cancelFollow(vlogerId) {
var me = this;
var userId = getApp().getUserInfoSession().id;
var serverUrl = app.globalData.serverUrl;
uni.request({
method: "POST",
header: {
headerUserId: userId,
headerUserToken: app.getUserSessionToken()
},
url: serverUrl + "/fans/cancel?myId=" + userId + "&vlogerId=" + vlogerId,
success(result) {
if (result.data.status == 200) {
me.reFreshList(vlogerId, false);
} else {
uni.showToast({
title: result.data.msg,
icon: "none",
duration: 3000
});
}
}
});
},
2.2. 取关~后端
/**
* 取关
*
* @param myId 我的用户ID
* @param vlogerId 视频发布者ID
* @return
*/
@PostMapping("cancel")
public GraceJSONResult cancel(@RequestParam String myId,
@RequestParam String vlogerId) {
// 删除业务的执行
fansService.doCancel(myId, vlogerId);
// 博主的粉丝-1,我的关注-1
//我的关注总数
redis.decrement(REDIS_MY_FOLLOWS_COUNTS + ":" + myId, 1);
// 博主的粉丝总数
redis.decrement(REDIS_MY_FANS_COUNTS + ":" + vlogerId, 1);
// 我和博主的关联关系,依赖redis,不要存储数据库,避免db的性能瓶颈
redis.del(REDIS_FANS_AND_VLOGGER_RELATIONSHIP + ":" + myId + ":" + vlogerId);
return GraceJSONResult.ok();
}
/** * 取关 * * @param myId 我的用户ID * @param vlogerId 视频发布者ID * @return */
@Transactional
@Override
public void doCancel(String myId, String vlogerId) {
// 判断我们是否朋友关系,如果是,则需要取消双方的关系
Fans fan = queryFansRelationship(myId, vlogerId);
if (fan != null && fan.getIsFanFriendOfMine() == YesOrNo.YES.type) {
// 抹除双方的朋友关系,自己的关系删除即可
Fans pendingFan = queryFansRelationship(vlogerId, myId);
pendingFan.setIsFanFriendOfMine(YesOrNo.NO.type);
fansMapper.updateByPrimaryKeySelective(pendingFan);
}
// 删除自己的关注关联表记录
fansMapper.delete(fan);
}
三、5217取关实战
3.1. 取关前资料分析
尾号~0009
关注:1
粉丝:2
尾号~5217
关注:3
粉丝:2



3.2. 账号5217取关
尾号~0009
关注:1
粉丝:1 ->由2变成了1
尾号~5217
关注:2 ->由3变成了2
粉丝:2
我关注的那一条数据删除了,博主和我不是朋友关系了
四、账号0009取关实战
4.1. 账号0009取关
尾号~0009
关注:0 由1变成了0
粉丝:1
尾号~5217
关注:2 ->由3变成了2
粉丝:1 ->由2变成了1

4.2. 数据变化
0009账号关注的信息也删除了
边栏推荐
- How the uni app automatically switches the requested address according to the environment
- English grammar_ Adjective / adverb Level 3 - Comparative
- 揭开SSL的神秘面纱,了解如何用SSL保护数据
- Staggered and permutation combination formula
- Pointer linked list
- Open the field of maker education and creation
- English grammar_ Adjective / adverb Level 3 - Comparative_ Useful Expressions
- Iso8191 test is mentioned in as 3744.1. Are the two tests the same?
- @Transactional失效的几种场景
- GenICam GenTL 标准 ver1.5(2)
猜你喜欢

多项目设计开发·类库项目引入入门

How to write a software test report? Here comes the third party performance report template

django. core. exceptions. ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3

《性能之巅第2版》阅读笔记(二)--性能观察工具

Principle and Simulation of switching power supply buck circuit

黑体辐射初探

La norme européenne en 597 - 1 pour les meubles est - elle la même que les deux normes en 597 - 2 pour les ignifuges?

iptables防火墙规则和firewalld防火墙规则详解

02 mongodb data types, important concepts and common shell instructions

光的粒子说(光电效应/康普顿效应)
随机推荐
ERP升级的另一种选择,MES系统
Leetcode: monotonic stack structure (Advanced)
多项目设计开发·类库项目引入入门
从零到一,教你搭建「以文搜图」搜索服务(一)
Particle theory of light (photoelectric effect / Compton effect)
[graduation season] graduate summary
第一章 Bash 入门
Introduction notes to machine learning
PostgreSQL implements batch update, deletion and insertion
等保三级密码复杂度是多少?多久更换一次?
Building a server monitoring platform with telegraf influxdb grafana
English grammar_ Adjective / adverb Level 3 - Comparative
applicationContext. Getbeansoftype obtains the execution methods of all implementation classes under an interface or obtains the operation application scenarios such as implementation class objects. L
欧洲家具EN 597-1 跟EN 597-2两个阻燃标准一样吗?
2021 year end summary and 2022 outlook
Uncover the mystery of SSL and learn how to protect data with SSL
A preliminary study of blackbody radiation
视频爆炸时代,谁在支撑视频生态网高速运行?
MSC 307(88) (2010 FTPC Code)第2部分烟气和毒性测试
02 mongodb data types, important concepts and common shell instructions