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

Silabs #274

Merged
merged 17 commits into from
Oct 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,7 @@ pipeline
stage('Check executable for Windows')
{
agent { label 'windows10' }
options { skipDefaultCheckout() }
steps
{
cleanWs()
Expand Down Expand Up @@ -304,6 +305,7 @@ pipeline
stage('Check executable for Mac')
{
agent { label 'bgbuild-mac' }
options { skipDefaultCheckout() }
steps
{
// WORKAROUND:
Expand Down Expand Up @@ -409,20 +411,20 @@ pipeline
[$class: 'DevelopersRecipientProvider']])

jobName = "${currentBuild.fullDisplayName}".replace('%2', '/')
if (currentBuild.result != 'SUCCESS') {
slackMessage = ":zap_failure: FAILED: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackColor = 'danger'
if (currentBuild.result == 'SUCCESS') {
slackMessage = ":zap_success: SUCCESS: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackColor = 'good'
slackSend (color: slackColor, channel: '#zap', message: slackMessage)
}
else if(currentBuild.result == 'UNSTABLE') {
slackMessage = ":warning: WARNING: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackMessage = ":zap_warning: WARNING: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackColor = 'warning'
slackSend (color: slackColor, channel: '#zap', message: slackMessage)
}
else
{
slackMessage = ":zap_success: SUCCESS: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackColor = 'good'
slackMessage = ":zap_failure: FAILED: <${env.RUN_DISPLAY_URL}|" + jobName + '>, changes by: ' + committers
slackColor = 'danger'
slackSend (color: slackColor, channel: '#zap', message: slackMessage)
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"type": "commonjs",
"name": "zap",
"version": "2021.10.21",
"version": "2021.10.29",
"description": "Configuration tool for the Zigbee Cluster Library",
"productName": "zap",
"cordovaId": "",
Expand Down
32 changes: 16 additions & 16 deletions src-electron/db/db-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ const fsp = require('fs').promises
const env = require('../util/env')
const util = require('../util/util.js')
const dbEnum = require('../../src-shared/db-enum.js')
const dbCache = require('./db-cache')

// This is a SQLITE specific thing. With SQLITE databases,
// we can't have multiple transactions. So this mechanism
Expand Down Expand Up @@ -149,7 +150,7 @@ async function dbRemove(db, query, args) {
env.logError(`Failed remove: ${query}: ${args}`)
reject(err)
} else {
env.logSql(`Executed remove: ${query}: ${args}`)
env.logSql('Executed remove', query, args)
resolve(this.changes)
}
})
Expand All @@ -172,7 +173,7 @@ async function dbUpdate(db, query, args) {
env.logError(`Failed update: ${query}: ${args}`)
reject(err)
} else {
env.logSql(`Executed update: ${query}: ${args}`)
env.logSql('Executed update', query, args)
resolve(this.changes)
}
})
Expand All @@ -195,9 +196,7 @@ async function dbInsert(db, query, args) {
env.logError(`Failed insert: ${query}: ${args} : ${err}`)
reject(err)
} else {
env.logSql(
`Executed insert: ${query}: ${args} => rowid: ${this.lastID}`
)
env.logSql('Executed insert', query, args)
resolve(this.lastID)
}
})
Expand All @@ -217,10 +216,10 @@ async function dbAll(db, query, args) {
return new Promise((resolve, reject) => {
db.all(query, args, (err, rows) => {
if (err) {
env.logSql(`Failed all: ${query}: ${args} : ${err}`)
env.logError(`Failed all: ${query}: ${args} : ${err}`)
reject(err)
} else {
env.logSql(`Executed all: ${query}: ${args}`)
env.logSql('Executed all', query, args)
resolve(rows)
}
})
Expand All @@ -243,7 +242,7 @@ async function dbGet(db, query, args, reportError = true) {
if (reportError) env.logError(`Failed get: ${query}: ${args} : ${err}`)
reject(err)
} else {
env.logSql(`Executed get: ${query}: ${args}`)
env.logSql('Executed get', query, args)
resolve(row)
}
})
Expand All @@ -260,9 +259,7 @@ async function dbGet(db, query, args, reportError = true) {
*/
async function dbMultiSelect(db, sql, arrayOfArrays) {
return new Promise((resolve, reject) => {
env.logSql(
`Preparing statement: ${sql} to select ${arrayOfArrays.length} rows.`
)
env.logSql('Preparing select', sql, arrayOfArrays.length)
let rows = []
let statement = db.prepare(sql, function (err) {
if (err) reject(err)
Expand Down Expand Up @@ -298,9 +295,7 @@ async function dbMultiSelect(db, sql, arrayOfArrays) {
*/
async function dbMultiInsert(db, sql, arrayOfArrays) {
return new Promise((resolve, reject) => {
env.logSql(
`Preparing statement: ${sql} to insert ${arrayOfArrays.length} records.`
)
env.logSql('Preparing insert', sql, arrayOfArrays.length)
let lastIds = []
let statement = db.prepare(sql, function (err) {
if (err) reject(err)
Expand All @@ -326,6 +321,7 @@ async function dbMultiInsert(db, sql, arrayOfArrays) {
* @returns A promise that resolves without an argument or rejects with error from the database closing.
*/
async function closeDatabase(database) {
dbCache.clear()
return new Promise((resolve, reject) => {
env.logSql('About to close database.')
database.close((err) => {
Expand All @@ -342,6 +338,7 @@ async function closeDatabase(database) {
* @param {*} database
*/
function closeDatabaseSync(database) {
dbCache.clear()
env.logSql('About to close database.')
database.close((err) => {
if (err) console.log(`Database close error: ${err}`)
Expand All @@ -355,6 +352,7 @@ function closeDatabaseSync(database) {
* @returns Promise that resolve with the Db.
*/
async function initRamDatabase() {
dbCache.clear()
return new Promise((resolve, reject) => {
let db = new sqlite.Database(':memory:', (err) => {
if (err) {
Expand All @@ -375,6 +373,7 @@ async function initRamDatabase() {
* @returns A promise that resolves with the database object that got created, or rejects with an error if something went wrong.
*/
async function initDatabase(sqlitePath) {
dbCache.clear()
return new Promise((resolve, reject) => {
let db = new sqlite.Database(sqlitePath, (err) => {
if (err) {
Expand Down Expand Up @@ -426,11 +425,12 @@ async function determineIfSchemaShouldLoad(db, context) {
}

async function updateCurrentSchemaCrc(db, context) {
return dbInsert(
await dbInsert(
db,
'INSERT OR REPLACE INTO PACKAGE (PATH, CRC, TYPE) VALUES ( ?, ?, ? )',
[context.filePath, context.crc, dbEnum.packageType.sqlSchema]
).then(() => context)
)
return context
}

async function performSchemaLoad(db, schemaContent) {
Expand Down
81 changes: 81 additions & 0 deletions src-electron/db/db-cache.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/**
*
* Copyright (c) 2021 Silicon Labs
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

/**
* This module provides cache for commonly used static database queries.
*
* @module DB API: zcl database access
*/
const dbApi = require('./db-api.js')
const dbMapping = require('./db-mapping.js')

const cacheEnabled = true
let cache = {}

/**
* Clears the entire cache.
*/
function clear() {
cache = {}
}

/**
* Puts a data object into the cache under a given key/packageId
* @param {*} key
* @param {*} packageId
* @param {*} data
*/
function put(key, packageId, data) {
const keyCache = {}
keyCache[packageId] = data
cache[key] = keyCache
}

/**
* Returns a data object under a given key/packageId.
*
* @param {*} key
* @param {*} packageId
* @returns cached object or null if none is present
*/
function get(key, packageId) {
const keyCache = cache[key]
if (keyCache != null) {
return keyCache[packageId]
} else {
return null
}
}

/**
* Returns true if a given key/packageId cache exists.
*
* @param {*} key
* @param {*} packageId
* @returns true or false, depending on whether the cache is present.
*/
function isCached(key, packageId) {
const keyCache = cache[key]
return keyCache != null && keyCache[packageId] != null
}

exports.clear = clear
exports.put = put
exports.get = get
exports.isCached = isCached

exports.cacheEnabled = cacheEnabled
1 change: 1 addition & 0 deletions src-electron/db/db-mapping.js
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ exports.map = {
atomic: (x) => {
if (x == null) return undefined
return {
id: x.ATOMIC_ID,
atomicId: x.ATOMIC_IDENTIFIER,
name: x.NAME,
description: x.DESCRIPTION,
Expand Down
Loading