diff --git a/backend/crud/bl-roomid-short.json b/backend/crud/bl-roomid-short.json deleted file mode 100644 index 03afd1d..0000000 --- a/backend/crud/bl-roomid-short.json +++ /dev/null @@ -1 +0,0 @@ -[240831, 5440, 0, 23058, 5446, 11893182, 7734200, 0, 0, 0, 504273, 1612585, 46938, 46936, 46937, 91625, 20006, 308892, 5090, 312785, 21551827, 21551833, 23755176, 13242892, 13242941, 21551834, 21622787, 21622784, 21622782, 21622781, 21622792, 21622795, 0, 21622803, 21622808, 21622811, 21496316, 0, 0, 0, 22462095, 0, 0, 0, 0, 0, 0, 0, 63727, 0, 0, 0, 0, 0, 910884, 21144080, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 14073662, 0, 0, 0, 0, 21686642, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 11218604, 127722, 0, 0, 5279, 34348, 18060, 5318, 0, 0, 0, 0, 5193, 15348, 0, 11598, 5170, 1016, 45104, 5082, 46716, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 10101, 0, 0, 0, 0, 0, 1029, 0, 0, 0, 0, 0, 0, 0, 24541, 10313, 54572, 78347, 0, 0, 44458, 0, 39936, 0, 0, 0, 0, 0, 96136, 35598, 0, 0, 75446, 32421, 0, 0, 0, 0, 0, 0, 0, 38227, 0, 0, 43001, 62565, 0, 0, 0, 0, 0, 64540, 0, 0, 0, 142902, 70270, 0, 0, 55634, 70155, 26416, 0, 263605, 0, 0, 90061, 94528, 0, 0, 101320, 0, 0, 56557, 0, 0, 0, 0, 0, 98608, 47867, 0, 66287, 0, 271425, 5294, 0, 272668, 53847, 0, 24589, 0, 97202, 44347, 0, 0, 0, 0, 0, 0, 22747055, 0, 0, 0, 75031, 0, 0, 0, 0, 0, 0, 39189, 0, 26057, 0, 32731, 258940, 0, 57690, 0, 109176, 0, 48743, 0, 0, 0, 0, 34180, 0, 0, 0, 234024, 0, 67336, 335045, 307467, 0, 54241, 430382, 527315, 0, 403237, 46353, 13566, 0, 0, 394518, 151159, 49728, 0, 0, 5077, 58881, 170908, 82393, 521429, 101609, 0, 157012, 0, 0, 0, 21715361, 0, 1004, 0, 35298, 0, 0, 0, 0, 0, 79558, 0, 371020, 0, 0, 67223, 55755, 43088, 151310, 95278, 74123, 39019, 30191, 56237, 0, 286893, 37034, 0, 0, 0, 0, 0, 0, 0, 0, 337374, 0, 0, 0, 0, 0, 0, 0, 0, 92075, 0, 0, 0, 0, 0, 0, 44592, 0, 0, 0, 0, 0, 53878, 0, 97835, 0, 0, 0, 0, 45827, 0, 0, 0, 0, 0, 60050, 382125, 1175880, 0, 0, 0, 0, 482156, 0, 0, 0, 0, 0, 0, 939654, 0, 0, 0, 1466954, 0, 0, 2696849, 280446, 5096, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5275, 0, 0, 40519, 0, 12265, 0, 0, 0, 149608, 0, 0, 182607, 314368, 0, 0, 3607547, 0, 3334931, 3514612, 0, 0, 933508, 0, 0, 0, 0, 0, 0, 0, 0, 0, 227311, 0, 1621877, 0, 0, 0, 4751957, 0, 3742025, 498388, 0, 0, 0, 0, 0, 56948, 1250611, 0, 0, 0, 11713, 0, 0, 52850, 179643, 0, 0, 0, 0, 543359, 17778, 763679, 0, 0, 37338, 36250, 193520, 0, 90713, 0, 3878601, 0, 55623, 92681, 101795, 0, 0, 0, 617484, 0, 0, 3017670, 100432, 0, 0, 0, 0, 0, 3495920, 0, 58725, 0, 360972, 0, 0, 0, 527395, 0, 926496, 0, 1327236, 1589452, 44221, 0, 0, 0, 0, 0, 0, 80397, 40764, 0, 29183, 0, 0, 868388, 0, 0, 424902, 0, 0, 0, 0, 0, 394681, 5311231, 100377, 5441, 1569975, 0, 22237, 0, 0, 0, 0, 0, 0, 0, 0, 1512103, 1161960, 0, 0, 4719881, 573893, 0, 0, 2785651, 284560, 0, 0, 10248, 175412, 11609, 25059330, 0, 5438584, 17793, 13074, 0, 0, 392351, 0, 0, 126556, 33671, 0, 0, 0, 0, 0, 0, 0, 4891501, 0, 0, 0, 0, 0, 0, 0, 98631, 0, 4288067, 0, 0, 0, 0, 0, 0, 0, 4720666, 47377, 0, 0, 0, 491683, 0, 0, 0, 0, 271628, 0, 0, 6374209, 919991, 0, 5257, 0, 0, 3975199, 92450, 0, 0, 0, 8016907, 1518632, 0, 0, 0, 0, 0, 0, 2339900, 0, 0, 0, 0, 0, 0, 41682, 869833, 0, 0, 5297, 5503854, 1315769, 5177, 0, 0, 0, 545352, 0, 0, 0, 21133, 0, 0, 0, 4350043, 61289, 0, 295476, 0, 0, 0, 0, 63129, 4631694, 0, 0, 0, 0, 544755, 10620, 452065, 0, 821119, 9115569, 0, 0, 0, 2303412, 443346, 0, 0, 0, 1722213, 53428, 313285, 0, 0, 0, 66251, 3807617, 91137, 0, 0, 883802, 3066386, 0, 544893, 919919, 3561767, 1005703, 433551, 1440094, 0, 11361154, 0, 29780, 1332655, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 516043, 3567937, 0, 0, 0, 44278, 82552, 0, 0, 7735393, 0, 0, 0, 1374115, 0, 0, 4306336, 0, 6154037, 12276230, 81711, 41729, 544609, 920309, 5054, 944865, 544780, 495714, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4010589, 544625, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 390638, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 99783, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7685334, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 21482915, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5612068, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5067] \ No newline at end of file diff --git a/backend/crud/database.go b/backend/crud/database.go index ed0a9b3..bbdf284 100644 --- a/backend/crud/database.go +++ b/backend/crud/database.go @@ -3,8 +3,6 @@ package crud import ( "context" _ "embed" - "encoding/json" - "fmt" "os" "go.mongodb.org/mongo-driver/mongo" @@ -17,12 +15,6 @@ var Client *mongo.Client var Coll *mongo.Collection var Sqldb *gorm.DB -//go:embed bl-roomid-short.json -var shortRoomidJson []byte - -// []uint32 actually -var ShortRoomid []int64 - func InitDatabase() { uri := os.Getenv("API_MONGO_URI") if uri == "" { @@ -40,10 +32,6 @@ func InitDatabase() { if err != nil { panic(err) } - - if err := json.Unmarshal(shortRoomidJson, &ShortRoomid); err != nil { - panic(fmt.Sprintf("Failed to parse embedded JSON file: %v", err)) - } } func DestoryDatabase() { diff --git a/backend/crud/streamer.go b/backend/crud/streamer.go index 4882e19..2774261 100644 --- a/backend/crud/streamer.go +++ b/backend/crud/streamer.go @@ -10,12 +10,13 @@ import ( ) type StreamerInfoDb struct { - Uid int64 - AreaName string `bson:"area_name"` - ParentName string `bson:"parent_name"` - Roomid int64 - Uname string - Id primitive.ObjectID `bson:"_id"` + Uid int64 + AreaName string `bson:"area_name"` + ParentName string `bson:"parent_name"` + Roomid int64 + ShortRoomid int64 `bson:"shortid"` + Uname string + Id primitive.ObjectID `bson:"_id"` } type StreamerInfo struct { @@ -51,7 +52,7 @@ func streamerByFilter(filter interface{}) []StreamerInfo { AreaName: e.AreaName, ParentName: e.ParentName, Roomid: e.Roomid, - ShortRoomid: 0, + ShortRoomid: e.ShortRoomid, Uname: e.Uname, FirstLogTs: uint32(e.Id.Timestamp().Unix()), }) @@ -59,36 +60,20 @@ func streamerByFilter(filter interface{}) []StreamerInfo { return results } -func StreamerByUid(uid int64) []StreamerInfo { - return streamerByFilter(bson.M{"uid": uid}) -} +// func StreamerByUid(uid int64) []StreamerInfo { +// return streamerByFilter(bson.M{"uid": uid}) +// } -func StreamerByRoomid(roomid int64) []StreamerInfo { - return streamerByFilter(bson.M{"roomid": roomid}) -} +// func StreamerByRoomid(roomid int64) []StreamerInfo { +// return streamerByFilter(bson.M{"roomid": roomid}) +// } func StreamerBy(id int64) []StreamerInfo { - var results []StreamerInfo - if id <= 1000 { - results = StreamerByUid(id) - origin_roomid := ShortRoomid[id] - // 0 means none, 1 ~ 1000 are reserved - if origin_roomid > 1000 { - if tmp := StreamerByRoomid(origin_roomid); tmp != nil { - // should be only 1 element - for _, e := range tmp { - e.ShortRoomid = id - results = append(results, e) - } - } - } - } else { - results = streamerByFilter(bson.M{ - "$or": []bson.M{ - {"uid": id}, - {"roomid": id}, - }, - }) - } - return results + return streamerByFilter(bson.M{ + "$or": []bson.M{ + {"uid": id}, + {"roomid": id}, + {"shortid": id}, + }, + }) }