Skip to content

Commit

Permalink
Merge branch 'main' into backend/release
Browse files Browse the repository at this point in the history
  • Loading branch information
Grvzard committed Oct 17, 2024
2 parents 66f4748 + 9b0055c commit 53e51df
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 14 deletions.
37 changes: 25 additions & 12 deletions backend/crud/streamlog.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ type StreamlogRow struct {
Cover string `json:"cover,omitempty"`
}

func FetchStreamLog(table string, uid int64, stop *time.Time) []StreamlogRow {
func FetchStreamLog(table string, uid int64, to_ *time.Time, from_ *time.Time) []StreamlogRow {
results := []StreamlogRow{}
if stop == nil {
Sqldb.Table(table).Where("uid = ?", uid).Order("_id DESC").Find(&results)
} else {
stopTstamp := uint32(stop.Unix())
Sqldb.Table(table).Where("uid = ?", uid).Where("last_update >= ?", stopTstamp).Order("_id DESC").Find(&results)
sql := Sqldb.Table(table).Where("uid = ?", uid)
if to_ != nil {
sql = sql.Where("last_update >= ?", uint32(to_.Unix()))
}
if from_ != nil {
sql = sql.Where("last_update <= ?", uint32(from_.Unix()))
}
sql.Order("_id DESC").Find(&results)
return results
}

Expand All @@ -36,22 +38,33 @@ func StreamLogByTstampSlice(uid int64, from uint32, to uint32) []StreamlogRow {
step := 1
// recent data are divided into tables by day (in tables like 2024_02_01)
// data prior to Stage1 are archived monthly (in tables like 2023_10)
is_orig_from := true
// critical values: to_ == from_ -> STOP
for to_.Before(from_) {
// critical values: from_ == Stage1 -> step 1
if from_.Before(config.GlobalConfig.Stage1) {
step = 2
}
if step == 1 {
tablename := from_.Format("2006_01_02")
// here we retrieve all entries regardless of the value of from/to
results = append(results, FetchStreamLog(tablename, uid, nil, nil)...)

from_ = from_.AddDate(0, 0, -1)
results = append(results, FetchStreamLog(tablename, uid, nil)...)
is_orig_from = false
} else if step == 2 {
tablename := from_.Format("2006_01")
from_ = from_.AddDate(0, -1, 0)
stop := to_
if from_.After(to_) {
stop = from_
// the search_to here might be smaller than the smallest value in the table,
// which introduces an overhead, but that's okay
search_to := &to_
search_from := &from_
if !is_orig_from {
search_from = nil
}
results = append(results, FetchStreamLog(tablename, uid, &stop)...)
results = append(results, FetchStreamLog(tablename, uid, search_to, search_from)...)

from_ = from_.AddDate(0, -1, 0)
is_orig_from = false
}
}
return results
Expand Down
5 changes: 4 additions & 1 deletion frontend/src/components/AppLayout.vue
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ function searchDebounce(q: string) {
function onInput(_event: any) {
setTimeout(searchDebounce, 300, search_text.value)
}
function onClickResult(streamer: StreamerInfo) {
emit('selectStreamer', streamer)
}
</script>

<template>
Expand Down Expand Up @@ -108,7 +111,7 @@ function onInput(_event: any) {
"{{ results_pattern }}" 搜索结果
</span>
<button v-for="streamer in search_results" :key="streamer.uid"
class="p-2 pl-3 rounded hover:bg-gray-200 text-left" @mousedown="$emit('selectStreamer', streamer)">
class="p-2 pl-3 rounded hover:bg-gray-200 text-left" @mousedown="onClickResult(streamer)">
{{ streamer.uname }} (房间号: {{ streamer.roomid }}
{{ streamer.short_roomid != 0 ? " / " + streamer.short_roomid : "" }})
</button>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/components/ResultTable.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ watch(dateRange, () => {
<tbody class="bg-white">
<tr v-for="row in streamlogData" :key="row.last_update">
<td class="Data-td text-cyan-600">
<a target="_blank" rel="noreferrer" :href="normalizeLink(row.cover)">链接</a>
<!-- 链接后的 hash tag 用于方便区分不同的封面链接 -->
<a target="_blank" rel="noreferrer" :href="normalizeLink(row.cover)">链接#{{ row.cover.slice(-6, -4) }}</a>
</td>
<td class="Data-td">
{{ row.title }}
Expand Down

0 comments on commit 53e51df

Please sign in to comment.