Skip to content

Commit 5b7b168

Browse files
committed
Merge remote-tracking branch 'origin/master' into chat-threads-smaller
2 parents 15cfcf5 + 74d461a commit 5b7b168

File tree

38 files changed

+561
-352
lines changed

38 files changed

+561
-352
lines changed

src/README.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ If you export the PORT environment variable, that determines what port everythin
6464

6565
CoCalc also runs a NATS server listening on two ports on localhost, one for TCP and one for WebSocket connections. To avoid conflicts, you can customize their ports by setting the environment variables `COCALC_NATS_PORT` (default 4222), and `COCALC_NATS_WS_PORT` (default 8443).
6666

67-
6867
**Note**: If you installed `pnpm` locally (instead of globally), simply run `npm run` in place of `pnpm` to execute
6968
these commands via [NPM run scripts](https://docs.npmjs.com/cli/v10/using-npm/scripts).
7069

@@ -144,7 +143,7 @@ You can also just type `pnpm psql` :
144143
~/cocalc/src$ pnpm psql
145144
```
146145

147-
NOTE: As of Jan 2023, CoCalc should fully work with any version of PostgreSQL from version 10.x onward. However, obviously at some point we will stop supporting PostgreSQL v 10.
146+
NOTE: As of Jan 2023, CoCalc should fully work with any version of PostgreSQL from version 14.x onward. However, obviously at some point we will stop supporting PostgreSQL v 14.
148147

149148
### 2. More about Starting the Hub
150149

@@ -186,6 +185,14 @@ which installs exactly the right packages, and builds the code.
186185

187186
See `packages/backend/data.ts` . In particular, you can set BASE_PATH, DATA, PGHOST, PGDATA, PROJECTS, SECRETS to override the defaults. Data is stored in `cocalc/src/data/` by default.
188187

188+
For NATS when doing development, it can be useful to set these in .bashrc so NATS uses ports of your choosing that are available.
189+
190+
```sh
191+
export COCALC_NATS_SERVER_NAME=localhost
192+
export COCALC_NATS_PORT=5007
193+
export COCALC_NATS_WS_PORT=5008
194+
```
195+
189196
#### File System Build Caching
190197

191198
There are two types of file system build caching. These greatly improve the time to compile typescript or start webpack between runs. However, in rare cases bugs may lead to weird broken behavior. Here's where the caches are, so you know how to clear them to check if this is the source of trouble. _As of now, I'm_ _**not**_ _aware of any bugs in file system caching._

src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
"build-dev": "./workspaces.py install && ./workspaces.py build --dev",
1010
"clean": "rm -rf packages/node_modules && ./workspaces.py clean && cd compute/compute && pnpm clean ",
1111
"hub": "cd packages/hub && npm run hub-project-dev-nobuild",
12+
"hub-prod": "cd packages/hub && npm run hub-project-prod-nobuild",
1213
"rspack": "cd packages/static && pnpm watch",
1314
"psql": "export PGHOST=${PGHOST:=$INIT_CWD/data/postgres/socket}; PGUSER='smc' psql",
1415
"database": "cd dev/project && ./start_postgres.py",

src/packages/backend/nats/test/time.test.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
DEVELOPMENT:
33
4-
pnpm exec jest --watch --forceExit --detectOpenHandles "time.test.ts"
4+
pnpm test ./time.test.ts
55
*/
66

77
// this sets client
@@ -28,3 +28,15 @@ describe("get time from nats", () => {
2828
expect(typeof time()).toBe("number");
2929
});
3030
});
31+
32+
import { timeClient, createTimeService } from "@cocalc/nats/service/time";
33+
34+
describe("start the time server and client and test that it works", () => {
35+
it("starts the time server and queries it", async () => {
36+
await import("@cocalc/backend/nats");
37+
createTimeService();
38+
const client = timeClient();
39+
const t = await client.time();
40+
expect(Math.abs(Date.now() - t)).toBeLessThan(200);
41+
});
42+
});

src/packages/database/postgres-user-queries.coffee

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,9 @@ exports.extend_PostgreSQL = (ext) -> class PostgreSQL extends ext
899899
# This will avoid a possible subtle edge case if user is cheating and always somehow
900900
# crashes server...?
901901
_user_set_query_project_change_before: (old_val, new_val, account_id, cb) =>
902-
dbg = @_dbg("_user_set_query_project_change_before #{account_id}, #{misc.to_json(old_val)} --> #{misc.to_json(new_val)}")
902+
#dbg = @_dbg("_user_set_query_project_change_before #{account_id}, #{misc.to_json(old_val)} --> #{misc.to_json(new_val)}")
903+
# I've seen MASSIVE OUTPUT from this, e.g., when setting avatar.
904+
dbg = @_dbg("_user_set_query_project_change_before #{account_id}")
903905
dbg()
904906

905907
if new_val?.name and (new_val?.name != old_val?.name)

src/packages/frontend/chat/message.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@ import { Name } from "./name";
4141
import { Time } from "./time";
4242
import { ChatMessageTyped, Mode, SubmitMentionsFn } from "./types";
4343
import {
44-
getReplyToRoot,
4544
getThreadRootDate,
4645
is_editing,
4746
message_colors,

src/packages/frontend/client/project.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ import httpApi from "./api";
5454
import { WebappClient } from "./client";
5555
import { throttle } from "lodash";
5656
import { writeFile, type WriteFileOptions } from "@cocalc/nats/files/write";
57+
import { readFile, type ReadFileOptions } from "@cocalc/nats/files/read";
5758

5859
export class ProjectClient {
5960
private client: WebappClient;
@@ -99,6 +100,18 @@ export class ProjectClient {
99100
return await writeFile(opts);
100101
};
101102

103+
// readFile -- read **arbitrarily large text or binary files**
104+
// from a project via a readable stream.
105+
// Look at the code below if you want to stream a file for memory
106+
// efficiency...
107+
readFile = async (opts: ReadFileOptions): Promise<Buffer> => {
108+
const chunks: Uint8Array[] = [];
109+
for await (const chunk of await readFile(opts)) {
110+
chunks.push(chunk);
111+
}
112+
return Buffer.concat(chunks);
113+
};
114+
102115
public async read_text_file({
103116
project_id,
104117
path,

src/packages/frontend/components/time-elapsed.tsx

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,32 @@
44
*/
55

66
import React from "react";
7-
import * as misc from "@cocalc/util/misc";
87
import { useInterval } from "react-interval-hook";
98

9+
import { seconds2hms, server_time } from "@cocalc/util/misc";
10+
1011
interface Props {
1112
start_ts: number;
1213
interval_s?: number;
1314
}
1415

15-
function isSame(prev, next) {
16-
if (prev == null || next == null) return false;
17-
return prev.start_ts != next.start_ts;
18-
}
19-
20-
export const TimeElapsed: React.FC<Props> = React.memo((props: Props) => {
21-
const { start_ts, interval_s = 1 } = props;
16+
export function TimeElapsed({ start_ts, interval_s = 1 }: Props) {
17+
const [elapsed, setElapsed] = React.useState<string>(getUptimeStr());
2218

23-
const [elapsed, setElapsed] = React.useState("");
19+
function getUptimeStr() {
20+
if (start_ts == null) return "";
21+
const delta_s = (server_time().getTime() - start_ts) / 1000;
22+
const uptime_str = seconds2hms(delta_s, true);
23+
return uptime_str;
24+
}
2425

2526
useInterval(() => {
26-
if (start_ts == null) return;
27-
const delta_s = (misc.server_time().getTime() - start_ts) / 1000;
28-
const uptime_str = misc.seconds2hms(delta_s, true);
29-
setElapsed(uptime_str);
27+
const next = getUptimeStr();
28+
if (!next) return;
29+
setElapsed(next);
3030
}, interval_s * 1000);
3131

3232
if (start_ts == null) return null;
3333

3434
return <React.Fragment>{elapsed}</React.Fragment>;
35-
}, isSame);
35+
}

src/packages/frontend/cspell.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"syncdoc",
3636
"syncdoc",
3737
"syncstring",
38+
"synctable",
3839
"synctables",
3940
"tidyverse",
4041
"timetravel",

0 commit comments

Comments
 (0)