Skip to content

Take task#2

Open
TCY1020 wants to merge 14 commits intomainfrom
takeTask
Open

Take task#2
TCY1020 wants to merge 14 commits intomainfrom
takeTask

Conversation

@TCY1020
Copy link
Owner

@TCY1020 TCY1020 commented Feb 1, 2024

  1. 變數,參數打全名、修改有Data的命名、統一小駝峰
  2. 一個function維持一個return
  3. pullSqlToRedis移到service下utils的common.js
  4. 新增helper裡的MessageFormatter、Pagination,減少重複性的程式碼
  5. 空行提升可讀性
  6. 多比數去包裝成一包請求寫入SQL
  7. 把之前的Passport套件跟程式碼刪除

messagesFromRedis = messageFormatter.getMessages();
} else {
const messageFormatter = new ctx.helper.MessageFormatter(messageOfRedis[0][1]);
messagesFromRedis = messageFormatter.getMessages();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if else都用到,可拉出來到外面

pruneMessages.forEach(async message => { await app.redis.rpush(`data_page${page}`, JSON.stringify(message)); });
await app.redis.expire(`data_page${page}`, 90);
console.log('往DB查');
class Pagination {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

一個檔案應只有一個class

const { comment } = ctx.request.body;
const { user } = ctx.session;
const { userId } = ctx.session;
const multi = app.redis.multi();
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哪裡用到放哪裡,multi是redis transaction指令,容易誤解接下來的redis指令是屬於multi的範圍

const { ctx } = this;
const { id } = ctx.params;
const multi = app.redis.multi();
const idNumberType = Number(id);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不直覺

this.messages = messages;
}
getMessage(id) {
return { index: id, message: JSON.parse(this.messages) };
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

這應該是message的邏輯

for (const edit of editFromRedis) {
const message = await Message.findByPk(edit.messageId);
await message.update({
const messageOfRedis = await app.redis.lpop('edit', 50);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

變數命名再想一下,需要更直覺

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

Successfully merging this pull request may close these issues.

2 participants