Skip to content

Commit

Permalink
actually resolve merge conflicts?
Browse files Browse the repository at this point in the history
  • Loading branch information
shelwinsunga committed Aug 6, 2024
2 parents 0980465 + 9115560 commit c50dde1
Show file tree
Hide file tree
Showing 5 changed files with 57 additions and 10 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,5 @@ dist

# Ignore static files
static/
*.db-shm
*.db-wal
23 changes: 20 additions & 3 deletions ell-studio/src/pages/Home.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React, { useState, useMemo, useEffect } from 'react';
import { Link } from 'react-router-dom';
import { useTheme } from '../contexts/ThemeContext';
import { getTimeAgo } from '../utils/lmpUtils';
Expand All @@ -10,6 +10,8 @@ import { Card, CardHeader, CardContent } from 'components/common/Card';
import { ScrollArea } from 'components/common/ScrollArea';
import { ResizablePanelGroup, ResizablePanel, ResizableHandle } from 'components/common/Resizable';

const MemoizedDependencyGraph = React.memo(DependencyGraph);

function Home() {
const [expandedLMP, setExpandedLMP] = useState(null);
const { darkMode } = useTheme();
Expand All @@ -27,7 +29,22 @@ function Home() {
return id.length > 8 ? `${id.substring(0, 8)}...` : id;
};

if (isLoadingLMPs || isLoadingTraces) {
const [firstTraces, setFirstTraces] = useState(traces);
const [firstLMPs, setFirstLMPs] = useState(lmps);

useEffect(() => {
if((!firstTraces || !firstLMPs) && traces && lmps) {
console.log("Setting first traces and lmps");
setFirstTraces(traces);
setFirstLMPs(lmps);
}
}, [traces, firstTraces, lmps, firstLMPs]);

// TODO: Make graph dynamically update.
const memoizedTraces = useMemo(() => firstTraces, [firstTraces]);
const memoizedLMPs = useMemo(() => firstLMPs, [firstLMPs]);

if (!memoizedLMPs || !memoizedTraces) {
return <div className={`bg-${darkMode ? 'gray-900' : 'gray-100'} min-h-screen flex items-center justify-center`}>
<p className={`text-${darkMode ? 'white' : 'black'}`}>Loading...</p>
</div>;
Expand All @@ -53,7 +70,7 @@ function Home() {
</div>
</div>
<div className="w-full h-full">
{lmps && traces && <DependencyGraph lmps={lmps} traces={traces}/>}
<MemoizedDependencyGraph lmps={memoizedLMPs} traces={memoizedTraces} key={memoizedLMPs.length + memoizedTraces.length}/>
</div>
</div>
</ResizablePanel>
Expand Down
Binary file removed examples/sqlite_example/ell.db-shm
Binary file not shown.
Empty file removed examples/sqlite_example/ell.db-wal
Empty file.
42 changes: 35 additions & 7 deletions src/ell/studio/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from fastapi.staticfiles import StaticFiles
from fastapi.responses import FileResponse
from watchfiles import awatch

import time

def main():
parser = ArgumentParser(description="ELL Studio Data Server")
Expand All @@ -30,20 +30,48 @@ async def serve_react_app(full_path: str):

db_path = os.path.join(args.storage_dir, "ell.db")

async def db_watcher():
async for changes in awatch(db_path):
print(f"Database changed: {changes}")
await app.notify_clients("database_updated")
async def db_watcher(db_path, app):
last_stat = None

# Start the database watcher
while True:
await asyncio.sleep(0.1) # Fixed interval of 0.1 seconds
try:
current_stat = os.stat(db_path)

if last_stat is None:
print(f"Database file found: {db_path}")
await app.notify_clients("database_updated")
else:
# Use a threshold for time comparison to account for filesystem differences
time_threshold = 1 # 1 second threshold
time_changed = abs(current_stat.st_mtime - last_stat.st_mtime) > time_threshold
size_changed = current_stat.st_size != last_stat.st_size
inode_changed = current_stat.st_ino != last_stat.st_ino

if time_changed or size_changed or inode_changed:
print(f"Database changed: mtime {time.ctime(last_stat.st_mtime)} -> {time.ctime(current_stat.st_mtime)}, "
f"size {last_stat.st_size} -> {current_stat.st_size}, "
f"inode {last_stat.st_ino} -> {current_stat.st_ino}")
await app.notify_clients("database_updated")

last_stat = current_stat
except FileNotFoundError:
if last_stat is not None:
print(f"Database file deleted: {db_path}")
await app.notify_clients("database_updated")
last_stat = None
await asyncio.sleep(1) # Wait a bit longer if the file is missing
except Exception as e:
print(f"Error checking database file: {e}")
await asyncio.sleep(1) # Wait a bit longer on errors

# Start the database watcher
loop = asyncio.new_event_loop()

config = uvicorn.Config(app=app, port=args.port, loop=loop)
server = uvicorn.Server(config)
loop.create_task(server.serve())
loop.create_task(db_watcher())
loop.create_task(db_watcher(db_path, app))
loop.run_forever()

if __name__ == "__main__":
Expand Down

0 comments on commit c50dde1

Please sign in to comment.