mirror of
https://git.maid.zone/stuff/soundcloak.git
synced 2025-12-10 05:39:38 +05:00
align structs for better memory layout
This commit is contained in:
@@ -105,4 +105,6 @@ If you want to add a new feature that's not in [the todo list](https://git.maid.
|
|||||||
|
|
||||||
If you have updated go dependencies or added new ones, please run `go mod tidy` before commiting.
|
If you have updated go dependencies or added new ones, please run `go mod tidy` before commiting.
|
||||||
|
|
||||||
|
If you update structs, please run [betteralign](https://github.com/dkorunic/betteralign) to make sure memory layout is optimized.
|
||||||
|
|
||||||
Any security vulnerabilities should first be disclosed privately to the maintainer ([different ways to contact me are listed here](https://laptopc.at))
|
Any security vulnerabilities should first be disclosed privately to the maintainer ([different ways to contact me are listed here](https://laptopc.at))
|
||||||
@@ -15,14 +15,14 @@ import (
|
|||||||
const defaultPartsCapacity = 24
|
const defaultPartsCapacity = 24
|
||||||
|
|
||||||
type reader struct {
|
type reader struct {
|
||||||
|
duration *uint32
|
||||||
|
|
||||||
|
req *fasthttp.Request
|
||||||
|
resp *fasthttp.Response
|
||||||
|
client *fasthttp.HostClient
|
||||||
parts [][]byte
|
parts [][]byte
|
||||||
leftover []byte
|
leftover []byte
|
||||||
index int
|
index int
|
||||||
duration *uint32
|
|
||||||
|
|
||||||
req *fasthttp.Request
|
|
||||||
resp *fasthttp.Response
|
|
||||||
client *fasthttp.HostClient
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var readerpool = sync.Pool{
|
var readerpool = sync.Pool{
|
||||||
|
|||||||
@@ -13,18 +13,18 @@ type PlaylistOrUser struct {
|
|||||||
Kind string `json:"kind"` // "playlist" or "system-playlist" or "user"
|
Kind string `json:"kind"` // "playlist" or "system-playlist" or "user"
|
||||||
Permalink string `json:"permalink"`
|
Permalink string `json:"permalink"`
|
||||||
|
|
||||||
// Playlist-specific
|
|
||||||
TrackCount int64 `json:"track_count"`
|
|
||||||
Title string `json:"title"`
|
|
||||||
Author struct {
|
|
||||||
Permalink string
|
|
||||||
} `json:"author"`
|
|
||||||
Artwork string `json:"artwork_url"`
|
|
||||||
|
|
||||||
// User-specific
|
// User-specific
|
||||||
Avatar string `json:"avatar_url"`
|
Avatar string `json:"avatar_url"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
|
|
||||||
|
// Playlist-specific
|
||||||
|
Title string `json:"title"`
|
||||||
|
Author struct {
|
||||||
|
Permalink string
|
||||||
|
} `json:"author"`
|
||||||
|
Artwork string `json:"artwork_url"`
|
||||||
|
TrackCount int64 `json:"track_count"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p PlaylistOrUser) Href() string {
|
func (p PlaylistOrUser) Href() string {
|
||||||
|
|||||||
@@ -18,9 +18,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
type clientIdCache struct {
|
type clientIdCache struct {
|
||||||
|
NextCheck time.Time
|
||||||
ClientID string
|
ClientID string
|
||||||
Version string
|
Version string
|
||||||
NextCheck time.Time
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var ClientIDCache clientIdCache
|
var ClientIDCache clientIdCache
|
||||||
@@ -342,9 +342,9 @@ func Resolve(cid string, path string, out any) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type Paginated[T any] struct {
|
type Paginated[T any] struct {
|
||||||
|
Next string `json:"next_href"`
|
||||||
Collection []T `json:"collection"`
|
Collection []T `json:"collection"`
|
||||||
Total int64 `json:"total_results"`
|
Total int64 `json:"total_results"`
|
||||||
Next string `json:"next_href"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Paginated[T]) Proceed(cid string, shouldUnfold bool) error {
|
func (p *Paginated[T]) Proceed(cid string, shouldUnfold bool) error {
|
||||||
|
|||||||
@@ -16,23 +16,21 @@ var playlistsCacheLock = &sync.RWMutex{}
|
|||||||
// Functions/structures related to playlists
|
// Functions/structures related to playlists
|
||||||
|
|
||||||
type Playlist struct {
|
type Playlist struct {
|
||||||
Artwork string `json:"artwork_url"`
|
Artwork string `json:"artwork_url"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Kind string `json:"kind"` // should always be "playlist"! or "system-playlist"
|
Kind string `json:"kind"` // should always be "playlist"! or "system-playlist"
|
||||||
LastModified string `json:"last_modified"`
|
LastModified string `json:"last_modified"`
|
||||||
Likes int64 `json:"likes_count"`
|
Permalink string `json:"permalink"`
|
||||||
Permalink string `json:"permalink"`
|
TagList string `json:"tag_list"`
|
||||||
//ReleaseDate string `json:"release_date"`
|
Title string `json:"title"`
|
||||||
TagList string `json:"tag_list"`
|
Type string `json:"set_type"`
|
||||||
Title string `json:"title"`
|
MissingTracks string `json:"-"`
|
||||||
Type string `json:"set_type"`
|
Tracks []Track `json:"tracks"`
|
||||||
Album bool `json:"is_album"`
|
Author User `json:"user"`
|
||||||
Author User `json:"user"`
|
Likes int64 `json:"likes_count"`
|
||||||
Tracks []Track `json:"tracks"`
|
TrackCount int64 `json:"track_count"`
|
||||||
TrackCount int64 `json:"track_count"`
|
Album bool `json:"is_album"`
|
||||||
|
|
||||||
MissingTracks string `json:"-"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetPlaylist(cid string, permalink string) (Playlist, error) {
|
func GetPlaylist(cid string, permalink string) (Playlist, error) {
|
||||||
|
|||||||
@@ -25,26 +25,26 @@ var tracksCacheLock = &sync.RWMutex{}
|
|||||||
|
|
||||||
type Track struct {
|
type Track struct {
|
||||||
Artwork string `json:"artwork_url"`
|
Artwork string `json:"artwork_url"`
|
||||||
Comments int `json:"comment_count"`
|
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Duration uint32 `json:"full_duration"`
|
|
||||||
Genre string `json:"genre"`
|
Genre string `json:"genre"`
|
||||||
Kind string `json:"kind"` // should always be "track"!
|
Kind string `json:"kind"` // should always be "track"!
|
||||||
LastModified string `json:"last_modified"`
|
LastModified string `json:"last_modified"`
|
||||||
License string `json:"license"`
|
License string `json:"license"`
|
||||||
Likes int64 `json:"likes_count"`
|
|
||||||
Permalink string `json:"permalink"`
|
Permalink string `json:"permalink"`
|
||||||
Played int64 `json:"playback_count"`
|
|
||||||
Reposted int64 `json:"reposts_count"`
|
|
||||||
TagList string `json:"tag_list"`
|
TagList string `json:"tag_list"`
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
ID json.Number `json:"id"`
|
ID json.Number `json:"id"`
|
||||||
Media Media `json:"media"`
|
|
||||||
Authorization string `json:"track_authorization"`
|
Authorization string `json:"track_authorization"`
|
||||||
Author User `json:"user"`
|
|
||||||
Policy TrackPolicy `json:"policy"`
|
Policy TrackPolicy `json:"policy"`
|
||||||
Station string `json:"station_permalink"`
|
Station string `json:"station_permalink"`
|
||||||
|
Media Media `json:"media"`
|
||||||
|
Author User `json:"user"`
|
||||||
|
Comments int `json:"comment_count"`
|
||||||
|
Likes int64 `json:"likes_count"`
|
||||||
|
Played int64 `json:"playback_count"`
|
||||||
|
Reposted int64 `json:"reposts_count"`
|
||||||
|
Duration uint32 `json:"full_duration"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type TrackPolicy string
|
type TrackPolicy string
|
||||||
@@ -89,8 +89,8 @@ type Stream struct {
|
|||||||
type Comment struct {
|
type Comment struct {
|
||||||
Kind string `json:"kind"` // "comment"
|
Kind string `json:"kind"` // "comment"
|
||||||
Body string `json:"body"`
|
Body string `json:"body"`
|
||||||
Timestamp int `json:"timestamp"`
|
|
||||||
Author User `json:"user"`
|
Author User `json:"user"`
|
||||||
|
Timestamp int `json:"timestamp"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Media) SelectCompatible(mode string, opus bool) (*Transcoding, string) {
|
func (m Media) SelectCompatible(mode string, opus bool) (*Transcoding, string) {
|
||||||
|
|||||||
@@ -23,21 +23,20 @@ type User struct {
|
|||||||
Avatar string `json:"avatar_url"`
|
Avatar string `json:"avatar_url"`
|
||||||
CreatedAt string `json:"created_at"`
|
CreatedAt string `json:"created_at"`
|
||||||
Description string `json:"description"`
|
Description string `json:"description"`
|
||||||
Followers int64 `json:"followers_count"`
|
|
||||||
Following int64 `json:"followings_count"`
|
|
||||||
FullName string `json:"full_name"`
|
FullName string `json:"full_name"`
|
||||||
Kind string `json:"kind"` // should always be "user"!
|
Kind string `json:"kind"` // should always be "user"!
|
||||||
LastModified string `json:"last_modified"`
|
LastModified string `json:"last_modified"`
|
||||||
Liked int64 `json:"likes_count"`
|
|
||||||
Permalink string `json:"permalink"`
|
Permalink string `json:"permalink"`
|
||||||
Playlists int64 `json:"playlist_count"`
|
|
||||||
Tracks int64 `json:"track_count"`
|
|
||||||
ID json.Number `json:"id"`
|
ID json.Number `json:"id"`
|
||||||
Username string `json:"username"`
|
Username string `json:"username"`
|
||||||
Verified bool `json:"verified"`
|
|
||||||
Station string `json:"station_permalink"`
|
Station string `json:"station_permalink"`
|
||||||
|
WebProfiles []Link `json:",omitempty"`
|
||||||
WebProfiles []Link `json:",omitempty"`
|
Followers int64 `json:"followers_count"`
|
||||||
|
Following int64 `json:"followings_count"`
|
||||||
|
Liked int64 `json:"likes_count"`
|
||||||
|
Playlists int64 `json:"playlist_count"`
|
||||||
|
Tracks int64 `json:"track_count"`
|
||||||
|
Verified bool `json:"verified"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type Link struct {
|
type Link struct {
|
||||||
@@ -54,10 +53,9 @@ const (
|
|||||||
|
|
||||||
// not worthy of its own file
|
// not worthy of its own file
|
||||||
type Repost struct {
|
type Repost struct {
|
||||||
Type RepostType
|
|
||||||
|
|
||||||
Track *Track // type == track-report
|
Track *Track // type == track-report
|
||||||
Playlist *Playlist // type == playlist-repost
|
Playlist *Playlist // type == playlist-repost
|
||||||
|
Type RepostType
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r Repost) Fix(prefs cfg.Preferences) {
|
func (r Repost) Fix(prefs cfg.Preferences) {
|
||||||
|
|||||||
2
main.go
2
main.go
@@ -554,13 +554,13 @@ Disallow: /`)
|
|||||||
|
|
||||||
if cfg.InstanceInfo {
|
if cfg.InstanceInfo {
|
||||||
type info struct {
|
type info struct {
|
||||||
|
DefaultPreferences cfg.Preferences
|
||||||
Commit string
|
Commit string
|
||||||
Repo string
|
Repo string
|
||||||
ProxyImages bool
|
ProxyImages bool
|
||||||
ProxyStreams bool
|
ProxyStreams bool
|
||||||
Restream bool
|
Restream bool
|
||||||
GetWebProfiles bool
|
GetWebProfiles bool
|
||||||
DefaultPreferences cfg.Preferences
|
|
||||||
EnableAPI bool
|
EnableAPI bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user