Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Addng WriteInstance into LocalInstance inheritance hierarchy #3325

Merged
merged 14 commits into from
Mar 14, 2022

Conversation

black32167
Copy link
Contributor

@black32167 black32167 commented Feb 12, 2022

Description

This PR implements #2991.

Test Plan

sc=require("{SC_REPO}/packages/sourcecred/dist/server/api.js")
i = sc.sourcecred.instance.writeInstance.getOriginWriteInstance("{SC_INSTANCE}")
i.writeLedger(new sc.sourcecred.ledger.ledger.Ledger())

@black32167
Copy link
Contributor Author

black32167 commented Feb 13, 2022

Some side notes (not necessarily need be addressed in this PR):

  1. createPluginDirectory method in writeInstance copied one from readInstance, except additionally it was creating the target directory, which feels like a 'storage' responsibility. So just removed createPluginDirectory it from WriteInstance.
  2. Noted that there is a ReadOnlyInstance interface but no ReadWriteInstance interface. Is it feasible to introduce one (unsure)?
  3. Selection of the serialization strategy does not feel as a responsibility of the *Instance. Maybe better to move this logic into something like StrategicStorage wrapper.

Copy link
Member

@blueridger blueridger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AMAZING! This is one of the most exciting contributions from a casual contributor that I've seen. Just a few minor comments and updated test plan recommendation:

on second thought, the new storage methods are experimental and we can rigorously test them later. The really important manual testing to do is regression testing for local instance. Here are the steps:

  1. Clone sourcecred/cred and checkout the gh-pages branch.
  2. yarn build in sourcecred/sourcecred
  3. scdev credrank in sourcecred/cred and verify no errors
    if you haven't set up the scdev alias, it represents node /Users/thena/workspace/sourcecred/packages/sourcecred/bin/sourcecred.js

packages/sourcecred/src/api/instance/writeInstance.js Outdated Show resolved Hide resolved
packages/sourcecred/src/api/instance/writeInstance.js Outdated Show resolved Hide resolved
@@ -14,6 +14,12 @@ const api: any = {...cloneDeep(base)};
import {LocalInstance} from "../../api/instance/localInstance";
api.instance.LocalInstance = LocalInstance;

import {getOriginWriteInstance} from "../../api/instance/writeInstance";
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've added factory methods here because when I tried to register writeInstance module in packages/sourcecred/src/api/lib/base.js, the build was failing with

sourcecred: [webpack-cli] ModuleNotFoundError: Module not found: Error: Can't resolve 'fs' in '/storage/projects/sourcecred/sourcecred-sources/node_modules/better-sqlite3/lib'
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/webpack/lib/Compilation.js:925:10
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/webpack/lib/NormalModuleFactory.js:401:22
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/webpack/lib/NormalModuleFactory.js:130:21
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/webpack/lib/NormalModuleFactory.js:224:22
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/neo-async/async.js:2830:7
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/neo-async/async.js:6877:13
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/webpack/lib/NormalModuleFactory.js:214:25
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/Resolver.js:213:14
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/Resolver.js:285:5
sourcecred:     at eval (eval at create (/storage/projects/sourcecred/sourcecred-sources/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/UnsafeCachePlugin.js:44:7
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/Resolver.js:285:5
sourcecred:     at eval (eval at create (/storage/projects/sourcecred/sourcecred-sources/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:15:1)
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/Resolver.js:285:5
sourcecred:     at eval (eval at create (/storage/projects/sourcecred/sourcecred-sources/node_modules/tapable/lib/HookCodeFactory.js:33:10), <anonymous>:27:1)
sourcecred:     at /storage/projects/sourcecred/sourcecred-sources/node_modules/enhanced-resolve/lib/DescriptionFilePlugin.js:67:43
sourcecred: resolve 'fs' in '/storage/projects/sourcecred/sourcecred-sources/node_modules/better-sqlite3/lib'
sourcecred:   Parsed request is a module
sourcecred:   using description file: /storage/projects/sourcecred/sourcecred-sources/node_modules/better-sqlite3/package.json (relative path: ./lib)
sourcecred:     Field 'browser' doesn't contain a valid alias configuration
sourcecred:     resolve as module
sourcecred:       /storage/projects/sourcecred/sourcecred-sources/node_modules/better-sqlite3/lib/node_modules doesn't exist or is not a directory
sourcecred:       /storage/projects/sourcecred/sourcecred-sources/node_modules/node_modules doesn't exist or is not a directory
sourcecred:       /storage/projects/sourcecred/node_modules doesn't exist or is not a directory
sourcecred:       /storage/projects/node_modules doesn't exist or is not a directory
sourcecred:       /storage/node_modules doesn't exist or is not a directory
sourcecred:       /node_modules doesn't exist or is not a directory
...

presumably because of specificity in the webpack.config.api.js configuration for base.js. Unsure if that is right or wrong, just noting.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other comment for solution. it is important that write instance is imported into base.js

@black32167 black32167 marked this pull request as ready for review February 15, 2022 10:43
@black32167
Copy link
Contributor Author

black32167 commented Feb 15, 2022

The manual testing is done, the output of the scdev credrank (run in the 'sourcecred/cred' repo, 'gh-pages' branch) was looking like:

  GO   credrank
  GO   load data
 DONE  load data: 2005ms
  GO   run CredRank
 DONE  run CredRank: 1m 6s
# Top Participants By Cred

| Description | Cred | % |
| --- | --- | --- |
### personal data ###
...
  GO   writing changes
 DONE  writing changes: 7400ms
 DONE  credrank: 1m 20s

Copy link
Member

@blueridger blueridger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I wrote these comments and then forget to hit send!

// Private Functions
//////////////////////////////

async readInstanceConfig(): Promise<InstanceConfig> {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the method blocking this file from being used in lib/base.js and here is the solution:

  1. move readInstanceConfig and imports from "../instanceConfig" to LocalInstance
  2. move the implementations of readContributionsInput and readGraphInput to the LocalInstance
  3. stub readContributionsInput and readGraphInput in WriteInstance with throw new Error("not implemented")

@@ -14,6 +14,12 @@ const api: any = {...cloneDeep(base)};
import {LocalInstance} from "../../api/instance/localInstance";
api.instance.LocalInstance = LocalInstance;

import {getOriginWriteInstance} from "../../api/instance/writeInstance";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see other comment for solution. it is important that write instance is imported into base.js

@black32167
Copy link
Contributor Author

black32167 commented Mar 1, 2022

Applied solution, just one question:

stub readContributionsInput and readGraphInput in WriteInstance with throw new Error("not implemented")

Do we need this step given that WriteInstance extends ReadInstance where these methods are already declared?

@blueridger
Copy link
Member

Ah good point! No, they wouldn't need stubbed again then.

@black32167
Copy link
Contributor Author

@blueridger is anything else needed to be done here?

@blueridger blueridger merged commit 0506e48 into main Mar 14, 2022
@blueridger blueridger deleted the black32167/2991-writeInstance-extends-readInstance branch March 14, 2022 16:20
@blueridger
Copy link
Member

Great work, this is so exciting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants