Skip to content

Commit

Permalink
fix: don't get table size for a file more than 5 gigs
Browse files Browse the repository at this point in the history
  • Loading branch information
frectonz committed Jun 14, 2024
1 parent 74b672e commit bdc4fb7
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 40 deletions.
19 changes: 13 additions & 6 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,9 @@ impl TheDB {
}

async fn table(&self, name: String) -> color_eyre::Result<responses::Table> {
let metadata = tokio::fs::metadata(&self.path).await?;
let more_than_five = metadata.len() > 5_000_000_000;

Ok(self
.conn
.call(move |conn| {
Expand All @@ -288,12 +291,16 @@ impl TheDB {
r.get::<_, i32>(0)
})?;

let table_size = conn.query_row(
"SELECT SUM(pgsize) FROM dbstat WHERE name = ?1",
[&name],
|r| r.get::<_, i64>(0),
)?;
let table_size = helpers::format_size(table_size as f64);
let table_size = if more_than_five {
"---".to_owned()
} else {
let table_size = conn.query_row(
"SELECT SUM(pgsize) FROM dbstat WHERE name = ?1",
[&name],
|r| r.get::<_, i64>(0),
)?;
helpers::format_size(table_size as f64)
};

let index_count = conn.query_row(
"SELECT count(*) FROM sqlite_master WHERE type='index' AND tbl_name=?1",
Expand Down
68 changes: 34 additions & 34 deletions ui/src/routeTree.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,60 +8,60 @@

// This file is auto-generated by TanStack Router

import { createFileRoute } from "@tanstack/react-router";
import { createFileRoute } from '@tanstack/react-router'

// Import Routes

import { Route as rootRoute } from "./routes/__root";
import { Route as rootRoute } from './routes/__root'

// Create Virtual Routes

const TablesLazyImport = createFileRoute("/tables")();
const QueryLazyImport = createFileRoute("/query")();
const IndexLazyImport = createFileRoute("/")();
const TablesLazyImport = createFileRoute('/tables')()
const QueryLazyImport = createFileRoute('/query')()
const IndexLazyImport = createFileRoute('/')()

// Create/Update Routes

const TablesLazyRoute = TablesLazyImport.update({
path: "/tables",
path: '/tables',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/tables.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/tables.lazy').then((d) => d.Route))

const QueryLazyRoute = QueryLazyImport.update({
path: "/query",
path: '/query',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/query.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/query.lazy').then((d) => d.Route))

const IndexLazyRoute = IndexLazyImport.update({
path: "/",
path: '/',
getParentRoute: () => rootRoute,
} as any).lazy(() => import("./routes/index.lazy").then((d) => d.Route));
} as any).lazy(() => import('./routes/index.lazy').then((d) => d.Route))

// Populate the FileRoutesByPath interface

declare module "@tanstack/react-router" {
declare module '@tanstack/react-router' {
interface FileRoutesByPath {
"/": {
id: "/";
path: "/";
fullPath: "/";
preLoaderRoute: typeof IndexLazyImport;
parentRoute: typeof rootRoute;
};
"/query": {
id: "/query";
path: "/query";
fullPath: "/query";
preLoaderRoute: typeof QueryLazyImport;
parentRoute: typeof rootRoute;
};
"/tables": {
id: "/tables";
path: "/tables";
fullPath: "/tables";
preLoaderRoute: typeof TablesLazyImport;
parentRoute: typeof rootRoute;
};
'/': {
id: '/'
path: '/'
fullPath: '/'
preLoaderRoute: typeof IndexLazyImport
parentRoute: typeof rootRoute
}
'/query': {
id: '/query'
path: '/query'
fullPath: '/query'
preLoaderRoute: typeof QueryLazyImport
parentRoute: typeof rootRoute
}
'/tables': {
id: '/tables'
path: '/tables'
fullPath: '/tables'
preLoaderRoute: typeof TablesLazyImport
parentRoute: typeof rootRoute
}
}
}

Expand All @@ -71,7 +71,7 @@ export const routeTree = rootRoute.addChildren({
IndexLazyRoute,
QueryLazyRoute,
TablesLazyRoute,
});
})

/* prettier-ignore-end */

Expand Down

0 comments on commit bdc4fb7

Please sign in to comment.