Skip to content

Commit

Permalink
migration: start migrating to Meteor 3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jankapunkt committed Dec 5, 2023
1 parent 150d40d commit 185d950
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 8 deletions.
43 changes: 43 additions & 0 deletions src/imports/api/mixins/asyncReadyMixin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const listKeys = (x= {}) => {

Check failure on line 1 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

'listKeys' is assigned a value but never used

Check failure on line 1 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Operator '=' must be spaced

Check failure on line 1 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

'listKeys' is assigned a value but never used

Check failure on line 1 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Operator '=' must be spaced
for (const nameKey in x) {
console.debug(nameKey, typeof x)

Check failure on line 3 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 3 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
}
}
export const asyncReadyMixin = function (options) {
const { name, run } = options
const body = run.toString().split(/\n+/g)
options.isAsyncReady = body[1].includes('return Promise.asyncApply(() => {')
addToList(name, options.isAsyncReady)

return options
}

const internal = { list: [] }

global.getAsyncReadySummary = ({ printNames } = {}) => {
const { list } = internal
const max = list.length
let ready = 0
list.forEach(([name, isReady]) => {
if (isReady) {
ready++
}
else if (printNames) {
console.log('Not Async Ready:', name)

Check failure on line 26 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 26 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
}
})
const notReady = max - ready
const divisor = max || 1
const notReadyPerc = 100 * notReady / divisor
const readyPerc = 100 * ready / divisor
console.log('-------------------')

Check failure on line 33 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 33 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
console.log('Async Ready Summary')

Check failure on line 34 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 34 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
console.log('-------------------')

Check failure on line 35 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 35 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
console.log('count', max)

Check failure on line 36 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 36 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
console.log('ready', ready, `(${readyPerc.toFixed(2)}%)`)

Check failure on line 37 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 37 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
console.log('todo!', notReady, `(${notReadyPerc.toFixed(2)}%)`)

Check failure on line 38 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement

Check failure on line 38 in src/imports/api/mixins/asyncReadyMixin.js

View workflow job for this annotation

GitHub Actions / Javascript lint

Unexpected console statement
}

const addToList = (name, isAsyncReady) => {
internal.list.push([name, isAsyncReady])
}
12 changes: 6 additions & 6 deletions src/imports/contexts/classroom/schoolclass/SchoolClass.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ SchoolClass.methods.get = {
schema: {
_id: String
},
run: onServer(function ({ _id }) {
run: onServer(async function ({ _id }) {
const { userId } = this
const query = {
$or: [
Expand Down Expand Up @@ -309,7 +309,7 @@ SchoolClass.methods.my = {
},
'ids.$': String
},
run: onServer(function ({ ids }) {
run: function myClasses ({ ids }) {
const { userId } = this
const query = {
$or: [
Expand All @@ -326,7 +326,7 @@ SchoolClass.methods.my = {
}

return getCollection(SchoolClass.name).find(query).fetch()
})
}
}

/**
Expand All @@ -343,7 +343,7 @@ SchoolClass.methods.create = {
'timeFrame.to': SchoolClass.schema['timeFrame.to']
},
role: UserUtils.roles.teacher,
run: onServer(function createClass ({ title, timeFrame }) {
run: onServer(async function createClass ({ title, timeFrame }) {
const { userId } = this
const SchoolClassCollection = getCollection(SchoolClass.name)
const insert = { title, createdBy: userId }
Expand Down Expand Up @@ -466,7 +466,7 @@ SchoolClass.publications.single = {
schema: {
_id: String
},
run: onServer(function ({ _id }) {
run: onServer(async function ({ _id }) {
const { userId } = this
const query = {
$or: [
Expand All @@ -483,7 +483,7 @@ SchoolClass.publications.single = {
SchoolClass.publications.my = {
name: 'schoolClass.publications.my',
schema: {},
run: onServer(function () {
run: onServer(async function () {
const { userId } = this
const query = {
$or: [
Expand Down
3 changes: 2 additions & 1 deletion src/imports/infrastructure/factories/createMethod.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ import { createMethodFactory } from 'meteor/leaonline:method-factory'
import { Schema } from '../../api/schema/Schema'
import { checkPermissions } from '../../api/mixins/checkPermissions'
import { logRuntimeEndpoints } from '../../api/mixins/logRuntimeEndpoints'
import { asyncReadyMixin } from '../../api/mixins/asyncReadyMixin'

export const createMethod = createMethodFactory({
schemaFactory: Schema.create,
mixins: [checkPermissions, logRuntimeEndpoints]
mixins: [asyncReadyMixin, checkPermissions, logRuntimeEndpoints]
})
3 changes: 2 additions & 1 deletion src/imports/infrastructure/factories/createPublication.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@ import { logError } from '../../api/errors/server/logerror'
import { addErrorDetails } from '../../api/errors/server/addErrorDetails'
import { createLog } from '../../api/log/createLog'
import { logRuntimeEndpoints } from '../../api/mixins/logRuntimeEndpoints'
import { asyncReadyMixin } from '../../api/mixins/asyncReadyMixin'

export const createPublication = createPublicationFactory({
schemaFactory: Schema.create,
mixins: [checkPermissions, logRuntimeEndpoints],
mixins: [asyncReadyMixin, checkPermissions, logRuntimeEndpoints],
onError (publicationRuntimeError) {
const env = this
error('runtime error catch in publication [', env._name, ']')
Expand Down
22 changes: 22 additions & 0 deletions src/server/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,25 @@ import '../imports/startup/server/system'
import '../imports/startup/server/accounts'
import '../imports/startup/server/plugins'
import '../imports/startup/server/contexts'

global.analyzeMigrations = () => {
const methods = Object.entries(Meteor.server.publish_handlers)
let count = 0
for (const [name, method] of methods) {
const isAsync = method.constructor.name === 'AsyncFunction'
if (!isAsync) {
console.log(name, isAsync)
count++
}
}

const asyncReady = {
count: methods.length - count,
perc: 100 * (methods.length - count) / (methods.length || 1)
}
const toMigrate = { count, perc: 100 * count / (methods.length || 1) }

console.debug('Methods sumary:', methods.length, 'methods')
console.debug('async-ready', asyncReady.count, `(${asyncReady.perc}%)`)
console.debug('to migrate', toMigrate.count, `(${toMigrate.perc}%)`)
}

0 comments on commit 185d950

Please sign in to comment.