Skip to content

Commit

Permalink
Upgrade after fixing memory leak
Browse files Browse the repository at this point in the history
  • Loading branch information
initialed85 committed Aug 23, 2024
1 parent a6abdf6 commit f91cb04
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 263 deletions.
52 changes: 40 additions & 12 deletions frontend/src/components/VideoTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,12 @@ export function VideoTable(props: VideoTableProps) {
params: {
query: {
camera_id__eq: props.cameraId || undefined,
started_at__gte: props.date ? `${props.date}T00:00:00+08:00` : undefined,
started_at__lte: props.date ? `${props.date}T23:59:59+08:00` : undefined,
started_at__gte: props.date
? `${props.date}T00:00:00+08:00`
: undefined,
started_at__lte: props.date
? `${props.date}T23:59:59+08:00`
: undefined,
started_at__desc: "",
},
},
Expand Down Expand Up @@ -99,19 +103,29 @@ export function VideoTable(props: VideoTableProps) {

const available = video?.status !== "recording";

const minutes = Math.floor((video?.duration || 0) / (1_000_000_000 * 60));
const seconds = Math.floor((video?.duration || 0) / 1_000_000_000 - minutes * 60);
const minutes = Math.floor(
(video?.duration || 0) / (1_000_000_000 * 60),
);
const seconds = Math.floor(
(video?.duration || 0) / 1_000_000_000 - minutes * 60,
);

const fileSize = (video?.file_size || 0.0).toFixed(2);

var cameraName =
video?.camera_id_object && video?.camera_id_object?.name ? video.camera_id_object.name : "-";
video?.camera_id_object && video?.camera_id_object?.name
? video.camera_id_object.name
: "-";

if (props.responsive) {
cameraName = cameraName[0];
}

const statusText = (video?.status ? video.status[0].toUpperCase() + video.status.slice(1) : "-").trim();
const statusText = (
video?.status
? video.status[0].toUpperCase() + video.status.slice(1)
: "-"
).trim();

const status =
statusText === "Recording" ? (
Expand All @@ -138,7 +152,11 @@ export function VideoTable(props: VideoTableProps) {

if (video?.thumbnail_name) {
thumbnail = (
<a target="_blank" rel="noreferrer" href={`/media/${video?.thumbnail_name}`}>
<a
target="_blank"
rel="noreferrer"
href={`/media/${video?.thumbnail_name}`}
>
<img
style={{ width: props.responsive ? 160 : 320 }}
alt={`still from ${video?.camera_id_object?.name} @ ${props.date} ${startedAt}`}
Expand All @@ -152,16 +170,20 @@ export function VideoTable(props: VideoTableProps) {
thumbnail = <ErrorOutlineOutlinedIcon />;
}

const rawClassNames = video.id && classNamesByVideoId.get(video.id)?.keys();
const classNames = (rawClassNames ? Array.from(rawClassNames).sort() : []).join(", ");
const rawClassNames =
video.id && classNamesByVideoId.get(video.id)?.keys();
const classNames = (
rawClassNames ? Array.from(rawClassNames).sort() : []
).join(", ");

return (
<tr key={video.id}>
<td>{cameraName}</td>
<td>
<Typography>
{startedAt.toTimeString().split(" ")[0]} <br />
{endedAt ? endedAt.toTimeString().split(" ")[0] : "-"} <br />
{endedAt ? endedAt.toTimeString().split(" ")[0] : "-"}{" "}
<br />
</Typography>
<Typography color="neutral">
{minutes}m{seconds}s
Expand All @@ -183,7 +205,11 @@ export function VideoTable(props: VideoTableProps) {
</td>
<td>
{available ? (
<a target="_blank" rel="noreferrer" href={`/media/${video?.file_name}`}>
<a
target="_blank"
rel="noreferrer"
href={`/media/${video?.file_name}`}
>
<CloudDownloadOutlinedIcon color={"success"} />
</a>
) : (
Expand All @@ -196,7 +222,9 @@ export function VideoTable(props: VideoTableProps) {
) : (
<tr>
<td colSpan={6}>
<Typography color={"neutral"}>(No videos for the selected camera / date)</Typography>
<Typography color={"neutral"}>
(No videos for the selected camera / date)
</Typography>
</td>
</tr>
)}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,19 @@ require (
github.com/go-chi/chi/v5 v5.1.0
github.com/gomodule/redigo v1.9.2
github.com/google/uuid v1.6.0
github.com/initialed85/djangolang v0.0.64
github.com/initialed85/djangolang v0.0.67
github.com/jackc/pgx/v5 v5.6.0
github.com/jmoiron/sqlx v1.4.0
github.com/lib/pq v1.10.9
golang.org/x/exp v0.0.0-20240823005443-9b4947da3948
gopkg.in/yaml.v2 v2.4.0
)

require (
github.com/go-test/deep v1.0.8 // indirect
github.com/jackc/pgtype v1.14.3 // indirect
github.com/jackc/puddle/v2 v2.2.1 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/paulmach/orb v0.11.1 // indirect
golang.org/x/sync v0.8.0 // indirect
)

require (
Expand Down
13 changes: 2 additions & 11 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA=
filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/Masterminds/semver/v3 v3.1.1/go.mod h1:VPu/7SZ7ePZ3QOrcuXROw5FAcLl4a0cBrbBpGY/8hQs=
github.com/alecthomas/assert/v2 v2.10.0 h1:jjRCHsj6hBJhkmhznrCzoNpbA3zqy0fYiUcYZP/GkPY=
Expand Down Expand Up @@ -28,8 +26,6 @@ github.com/go-chi/chi/v5 v5.1.0 h1:acVI1TYaD+hhedDJ3r54HyA6sExp3HfXq7QWEEY/xMw=
github.com/go-chi/chi/v5 v5.1.0/go.mod h1:DslCQbL2OYiznFReuXYUmQ2hGd1aDpCnlMNITLSKoi8=
github.com/go-kit/log v0.1.0/go.mod h1:zbhenjAZHb184qTLMA9ZjW7ThYL0H2mk7Q6pNt4vbaY=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y=
github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg=
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
github.com/go-test/deep v1.0.7/go.mod h1:QV8Hv/iy04NyLBxAdO9njL0iVPN1S4d/A3NVv1V36o8=
github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
Expand All @@ -53,8 +49,8 @@ github.com/gorilla/websocket v1.5.3 h1:saDtZ6Pbx/0u+bgYQ3q96pZgCzfhKXGPqt7kZ72aN
github.com/gorilla/websocket v1.5.3/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
github.com/hexops/gotextdiff v1.0.3 h1:gitA9+qJrrTCsiCl7+kh75nPqQt1cx4ZkudSTLoUqJM=
github.com/hexops/gotextdiff v1.0.3/go.mod h1:pSWU5MAI3yDq+fZBTazCSJysOMbxWL1BSow5/V2vxeg=
github.com/initialed85/djangolang v0.0.64 h1:FsK5TtPtV2tSpSBAiTrnuRzXj5Kz77WSRfqO1geVUZ0=
github.com/initialed85/djangolang v0.0.64/go.mod h1:dNv0Y77p1Lgzs6A4eJoyTQqFOrvkUqOi49piz/kMSgw=
github.com/initialed85/djangolang v0.0.67 h1:Y+IhKGvk7V6N5kmNZJTE/gO2UaVa4IzSeg+EvJDhdTU=
github.com/initialed85/djangolang v0.0.67/go.mod h1:EFbZ1Utc3A1woO6fSygSmD2XuBQIbJDTkqv79mCELrc=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7 h1:G9Z1k4TyxQ/9Kk4ZSuw82WZCxJayZf12Aos2MorzKRg=
github.com/initialed85/structmeta v0.0.0-20240802152142-39f398ef1ab7/go.mod h1:hTGWTsfgy6Um+L8e3Qcj8/pBkHGcIGxEpZAKziWhQfc=
github.com/jackc/chunkreader v1.0.0 h1:4s39bBR8ByfqH+DKm8rQA3E1LHZWB9XWcrz8fqaZbe0=
Expand Down Expand Up @@ -126,7 +122,6 @@ github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0f
github.com/jackc/puddle v1.1.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.1.3/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle v1.3.0 h1:eHK/5clGOatcjX3oWGBO/MpxpbHzSwud5EWTSCI+MX0=
github.com/jackc/puddle v1.3.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk=
github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk=
github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4=
Expand All @@ -135,8 +130,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
github.com/jinzhu/now v1.1.1/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down Expand Up @@ -167,8 +160,6 @@ github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hd
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
github.com/mattn/go-sqlite3 v1.14.22 h1:2gZY6PC6kBnID23Tichd1K+Z0oS6nE/XwU+Vz/5o4kU=
github.com/mattn/go-sqlite3 v1.14.22/go.mod h1:Uh1q+B4BYcTPb+yiD3kU8Ct7aC0hY9fxUwlHK0RXw+Y=
github.com/modern-go/concurrent v0.0.0-20180228061459-e0a39a4cb421/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd h1:TRLaZ9cD/w8PVh93nsPXa1VrQ6jlwL5oN8l14QlcNfg=
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd/go.mod h1:6dJC0mAP4ikYIbvyc7fijjWJddQyLn8Ig3JB5CqoB9Q=
Expand Down
6 changes: 3 additions & 3 deletions pkg/api/0_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

"github.com/gomodule/redigo/redis"
"github.com/initialed85/djangolang/pkg/helpers"
"github.com/jmoiron/sqlx"
"github.com/jackc/pgx/v5/pgxpool"
"gopkg.in/yaml.v2"
)

Expand Down Expand Up @@ -44,7 +44,7 @@ func RunServeWithArguments(
ctx context.Context,
cancel context.CancelFunc,
port uint16,
db *sqlx.DB,
db *pgxpool.Pool,
redisPool *redis.Pool,
) {
defer cancel()
Expand Down Expand Up @@ -74,7 +74,7 @@ func RunServeWithEnvironment() {
log.Fatalf("err: %v", err)
}
defer func() {
_ = db.Close()
db.Close()
}()

go func() {
Expand Down
8 changes: 4 additions & 4 deletions pkg/api/0_meta.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"github.com/initialed85/djangolang/pkg/openapi"
"github.com/initialed85/djangolang/pkg/server"
"github.com/initialed85/djangolang/pkg/types"
"github.com/jmoiron/sqlx"
"github.com/jackc/pgx/v5/pgxpool"
"gopkg.in/yaml.v2"

"net/http/pprof"
Expand Down Expand Up @@ -82,7 +82,7 @@ func NewFromItem(tableName string, item map[string]any) (any, error) {
return newFromItemFn(item)
}

func GetRouter(db *sqlx.DB, redisPool *redis.Pool, httpMiddlewares []server.HTTPMiddleware, objectMiddlewares []server.ObjectMiddleware, waitForChange server.WaitForChange) chi.Router {
func GetRouter(db *pgxpool.Pool, redisPool *redis.Pool, httpMiddlewares []server.HTTPMiddleware, objectMiddlewares []server.ObjectMiddleware, waitForChange server.WaitForChange) chi.Router {
r := chi.NewRouter()

for _, m := range httpMiddlewares {
Expand All @@ -108,7 +108,7 @@ func GetRouter(db *sqlx.DB, redisPool *redis.Pool, httpMiddlewares []server.HTTP
}

lastHealthz = func() error {
err := db.PingContext(ctx)
err := db.Ping(ctx)
if err != nil {
return fmt.Errorf("db ping failed: %v", err)
}
Expand Down Expand Up @@ -207,7 +207,7 @@ func RunServer(
ctx context.Context,
changes chan server.Change,
addr string,
db *sqlx.DB,
db *pgxpool.Pool,
redisPool *redis.Pool,
httpMiddlewares []server.HTTPMiddleware,
objectMiddlewares []server.ObjectMiddleware,
Expand Down
Binary file modified pkg/api/bin/api
Binary file not shown.
Loading

0 comments on commit f91cb04

Please sign in to comment.