Browse Source

feat: show new message count & new user count in home page

JustSong 2 years ago
parent
commit
f5977581d3
5 changed files with 23 additions and 1 deletions
  1. 2 0
      common/constants.go
  2. 1 0
      controller/message.go
  3. 2 0
      controller/misc.go
  4. 3 0
      model/user.go
  5. 15 1
      web/src/pages/Home/index.js

+ 2 - 0
common/constants.go

@@ -11,6 +11,8 @@ var Version = "v0.0.0"
 var SystemName = "消息推送服务"
 var ServerAddress = "http://localhost:3000"
 var Footer = ""
+var MessageCount = 0 // Non critical value, no need to use atomic
+var UserCount = 0    // Non critical value, no need to use atomic
 
 // Any options with "Secret", "Token" in its key won't be return by GetOptions
 

+ 1 - 0
controller/message.go

@@ -153,6 +153,7 @@ func saveAndSendMessage(user *model.User, message *model.Message) error {
 		message.Link = "unsaved" // This is for user to identify whether the message is saved
 	}
 	err := channel.SendMessage(message, user)
+	common.MessageCount += 1 // We don't need to use atomic here because it's not a critical value
 	if err != nil {
 		return err
 	}

+ 2 - 0
controller/misc.go

@@ -28,6 +28,8 @@ func GetStatus(c *gin.Context) {
 			"turnstile_site_key":  common.TurnstileSiteKey,
 			"message_persistence": common.MessagePersistenceEnabled,
 			"message_render":      common.MessageRenderEnabled,
+			"message_count":       common.MessageCount,
+			"user_count":          common.UserCount,
 		},
 	})
 	return

+ 3 - 0
model/user.go

@@ -103,6 +103,9 @@ func (user *User) Insert() error {
 		}
 	}
 	err = DB.Create(user).Error
+	if err == nil {
+		common.UserCount += 1 // We don't need to use atomic here, because it's not a critical value
+	}
 	return err
 }
 

+ 15 - 1
web/src/pages/Home/index.js

@@ -47,10 +47,12 @@ const Home = () => {
                       href='https://github.com/songquanpeng/message-pusher'
                       target='_blank'
                     >
-                      GitHub 仓库地址
+                      https://github.com/songquanpeng/message-pusher
                     </a>
                   </p>
                   <p>启动时间:{getStartTimeString()}</p>
+                  <p>自从上次启动已发送消息数目:{statusState?.status?.message_count}</p>
+                  <p>自从上次启动新注册用户数目:{statusState?.status?.user_count}</p>
                 </Card.Description>
               </Card.Content>
             </Card>
@@ -85,6 +87,18 @@ const Home = () => {
                       ? '已启用'
                       : '未启用'}
                   </p>
+                  <p>
+                    全局消息持久化:
+                    {statusState?.status?.message_persistence === true
+                      ? '已启用'
+                      : '未启用'}
+                  </p>
+                  <p>
+                    全局消息渲染:
+                    {statusState?.status?.message_render === true
+                      ? '已启用'
+                      : '未启用'}
+                  </p>
                 </Card.Description>
               </Card.Content>
             </Card>