Add lean mode (overpass source and no map view in frontend)
This commit is contained in:
parent
d10b91804c
commit
3ef6dcf5d9
|
@ -4,6 +4,7 @@ DEBUG = True
|
|||
VERBOSE = False
|
||||
AUTO_RESTART = True
|
||||
SECRET = "!!!!!!!!!!!!CHANGE ME!!!!!!!!!!!!"
|
||||
LEAN_MODE = True
|
||||
POSTGRES_URL = "postgresql+asyncpg://obs:obs@postgres/obs"
|
||||
POSTGRES_POOL_SIZE = 20
|
||||
POSTGRES_MAX_OVERFLOW = 2 * POSTGRES_POOL_SIZE
|
||||
|
|
|
@ -7,6 +7,11 @@ DEBUG = False
|
|||
VERBOSE = DEBUG
|
||||
AUTO_RESTART = DEBUG
|
||||
|
||||
# Turn on lean mode to simplify the setup. Lots of features will be
|
||||
# unavailable, but you will not need to manage OpenStreetMap data. Please make
|
||||
# sure to configure the OBS_FACE_CACHE_DIR correctly for lean mode.
|
||||
LEAN_MODE = False
|
||||
|
||||
# Required to encrypt or sign sessions, cookies, tokens, etc.
|
||||
SECRET = "!!!<<<CHANGEME>>>!!!"
|
||||
|
||||
|
|
|
@ -25,7 +25,7 @@ from obs.face.filter import (
|
|||
RequiredFieldsFilter,
|
||||
)
|
||||
|
||||
from obs.face.osm import DataSource, DatabaseTileSource
|
||||
from obs.face.osm import DataSource, DatabaseTileSource, OverpassTileSource
|
||||
|
||||
from obs.api.db import OvertakingEvent, Track, make_session
|
||||
from obs.api.app import app
|
||||
|
@ -33,6 +33,20 @@ from obs.api.app import app
|
|||
log = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def get_data_source():
|
||||
"""
|
||||
Creates a data source based on the configuration of the portal. In *lean*
|
||||
mode, the OverpassTileSource is used to fetch data on demand. In normal
|
||||
mode, the roads database is used.
|
||||
"""
|
||||
if app.config.LEAN_MODE:
|
||||
tile_source = OverpassTileSource(cache_dir=app.config.OBS_FACE_CACHE_DIR)
|
||||
else:
|
||||
tile_source = DatabaseTileSource()
|
||||
|
||||
return DataSource(tile_source)
|
||||
|
||||
|
||||
async def process_tracks_loop(delay):
|
||||
while True:
|
||||
try:
|
||||
|
@ -50,9 +64,7 @@ async def process_tracks_loop(delay):
|
|||
await asyncio.sleep(delay)
|
||||
continue
|
||||
|
||||
tile_source = DatabaseTileSource()
|
||||
data_source = DataSource(tile_source)
|
||||
|
||||
data_source = get_data_source()
|
||||
await process_track(session, track, data_source)
|
||||
except BaseException:
|
||||
log.exception("Failed to process track. Will continue.")
|
||||
|
@ -66,8 +78,7 @@ async def process_tracks(tracks):
|
|||
|
||||
:param tracks: A list of strings which
|
||||
"""
|
||||
tile_source = DatabaseTileSource()
|
||||
data_source = DataSource(tile_source)
|
||||
data_source = get_data_source()
|
||||
|
||||
async with make_session() as session:
|
||||
for track_id_or_slug in tracks:
|
||||
|
|
|
@ -6,6 +6,7 @@ from sanic.exceptions import NotFound
|
|||
from obs.api.app import app
|
||||
|
||||
if app.config.FRONTEND_CONFIG:
|
||||
|
||||
@app.get("/config.json")
|
||||
def get_frontend_config(req):
|
||||
result = {
|
||||
|
@ -13,7 +14,10 @@ if app.config.FRONTEND_CONFIG:
|
|||
**req.app.config.FRONTEND_CONFIG,
|
||||
"apiUrl": f"{req.ctx.api_url}/api",
|
||||
"loginUrl": f"{req.ctx.api_url}/login",
|
||||
"obsMapSource": {
|
||||
"obsMapSource": (
|
||||
None
|
||||
if app.config.LEAN_MODE
|
||||
else {
|
||||
"type": "vector",
|
||||
"tiles": [
|
||||
req.ctx.api_url
|
||||
|
@ -24,7 +28,8 @@ if app.config.FRONTEND_CONFIG:
|
|||
],
|
||||
"minzoom": 12,
|
||||
"maxzoom": 14,
|
||||
},
|
||||
}
|
||||
),
|
||||
}
|
||||
|
||||
return response.json(result)
|
||||
|
|
|
@ -59,6 +59,8 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
|||
const config = useConfig()
|
||||
const apiVersion = useObservable(() => from(api.get('/info')).pipe(pluck('version')))
|
||||
|
||||
const hasMap = Boolean(config?.obsMapSource)
|
||||
|
||||
React.useEffect(() => {
|
||||
api.loadUser()
|
||||
}, [])
|
||||
|
@ -72,7 +74,7 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
|||
OpenBikeSensor
|
||||
</Link>
|
||||
|
||||
{config?.obsMapSource && (
|
||||
{hasMap && (
|
||||
<Link component={MenuItemForLink} to="/map" as="a">
|
||||
Map
|
||||
</Link>
|
||||
|
@ -110,9 +112,9 @@ const App = connect((state) => ({login: state.login}))(function App({login}) {
|
|||
<Route path="/" exact>
|
||||
<HomePage />
|
||||
</Route>
|
||||
<Route path="/map" exact>
|
||||
{hasMap && <Route path="/map" exact>
|
||||
<MapPage />
|
||||
</Route>
|
||||
</Route>}
|
||||
<Route path="/tracks" exact>
|
||||
<TracksPage />
|
||||
</Route>
|
||||
|
|
Loading…
Reference in a new issue