Skip to content

As Pryv dev, I need a cleaner, simpler codebase (follow-up) #507

@sgoumaz

Description

@sgoumaz

Follow-up from #463

  • Check code coverage and possibly remove dead code
  • Refactor hfs-server to update event durations in a simpler way (and get rid of all the bloat like tprpc…) ⚠️ First see about replacing InfluxDB with SQLite???
  • Review code structure consistency: there's an issue with conflictual (non-orthogonal) aspects, e.g. what exactly differentiates "business" from "platform"?
  • Check openSource/dnsLess settings disseminated all around: ultimately core must be DNS-less and that logic belongs to Nginx
  • Check code internals like supposedly private members (e.g. mall.stores) being routinely used elsewhere (and not only in tests, which is bad enough) – clean up components encapsulation
  • See root await & Unify singleton patterns (possible solutions below)
  • Consider cleaning up api-server tests organisation: test/ vs acceptance/, unit/ etc.
  • Similarly, consider Refactor: data stores knowledge must be confined to storage (mall) #435

Possible solutions for singletons

Just unify current singleton patterns, e.g.

const lazyInit = (fn) => {
	let promise = undefined;
	return () => promise = (promise || fn());
}

const getVersion = lazyInit(async () => {
	const programVersion = await version();

	return programVersion;
});

console.log(`Version is: ${await getVersion()}`);

Top-level await

  • Pro: cleanest ultimately
  • Con: loads of work

Init all at boot, then just synchronous require() (this is actually partially used in Application.js)

  • Con: then all exposed methods must check for init state…

Broken encapsulation of components code

Other components referencing each other's internal code… the mess! E.g. this example found in components/audit/src/methods/audit-logs.js:

const commonFns = require('api-server/src/methods/helpers/commonFunctions');
const methodsSchema = require('../schema/auditMethods');
const eventsGetUtils = require('api-server/src/methods/helpers/eventsGetUtils');
const mallEventsGetUtils = require('mall/src/lib/eventsGetUtils');
  
import type { GetEventsParams } from 'api-server/src/methods/helpers/eventsGetUtils';
import type { StreamQuery } from 'business/src/events';

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Ready

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions