Skip to content

Commit

Permalink
v17.0.7b
Browse files Browse the repository at this point in the history
- Relevant performance improvement (+ bugfix) on lists indexing.
- Fixed back button for Android devices.
  • Loading branch information
EdenwareApps committed Jul 24, 2023
1 parent 6c4c61f commit 9d243dc
Show file tree
Hide file tree
Showing 19 changed files with 204 additions and 134 deletions.
2 changes: 1 addition & 1 deletion www/nodejs-project/assets/js/app/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ function initApp(){
console.log('FFmpeg checking succeeded', ret)
}).catch(err => {
console.error('FFmpeg checking error')
osd.show(String(err), 'fas fa-exclamation-triagle faclr-red', 'ffmpeg-dl', 'normal')
osd.show(String(err), 'fas fa-exclamation-triangle faclr-red', 'ffmpeg-dl', 'normal')
})
})
}
Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-project/assets/js/index/electron.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class FFmpegDownloader {
let err
const file = await this.download(folder, osd, mask).catch(e => err = e)
if (err) {
osd.show(String(err), 'fas fa-exclamation-triagle faclr-red', 'ffmpeg-dl', 'normal')
osd.show(String(err), 'fas fa-exclamation-triangle faclr-red', 'ffmpeg-dl', 'normal')
} else {
osd.show(mask.replace('{0}', '100%'), 'fas fa-circle-notch fa-spin', 'ffmpeg-dl', 'normal')
this.executableDir = path.dirname(file)
Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-project/assets/js/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ document.addEventListener('resume', function () {
document.addEventListener('backbutton', function (e) {
if (app) {
e.preventDefault();
app.contentWindow.postMessage({ action: 'backbutton' }, location.origin);
app.postMessage({ action: 'backbutton' }, location.origin);
}
}, false);

Expand Down
3 changes: 3 additions & 0 deletions www/nodejs-project/modules/bridge/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ function frontendBackendReadyCallback(origin){
frontendBackendReady.backendCallbacks.forEach(f => f())
frontendBackendReady.backendCallbacks = []
}
if(!app) {
app = document.querySelector('iframe').contentWindow
}
if(frontendBackendReady.frontend && frontendBackendReady.backend){
app.lang = lang
app.config = config
Expand Down
3 changes: 1 addition & 2 deletions www/nodejs-project/modules/diagnostics/diagnostics.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ class Diagnostics extends Events {
const listsRequesting = global.lists.requesting
const tuning = global.tuning ? global.tuning.logText(false) : ''
const processedLists = global.lists.processedLists.keys();
const processing = global.lists.loader.processes.map(p => {
const processing = global.lists.loader.processes.filter(p => p.started() && !p.done()).map(p => {
return {
url: p.url,
started: p.started(),
priority: p.priority
}
});
Expand Down
5 changes: 3 additions & 2 deletions www/nodejs-project/modules/discovery/discovery.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ class PublicIPTVListsDiscovery extends Events {
const sortedLists = this.knownLists
// .filter(list => this.opts.countries.includes(list.country))
.sort((a, b) => {
if (a.health === -1 && b.health === -1) return 0
if (a.health === -1) return 1
if (b.health === -1) return -1
return b.health - a.health
return b.health > a.health ? 1 : (b.health < a.health ? -1 : 0)
})
return this.domainCap(sortedLists, amount)
}
Expand Down Expand Up @@ -102,7 +103,7 @@ class PublicIPTVListsDiscovery extends Events {
})
Object.keys(domains).forEach(dn => domains[dn] = 0) // reset counts and go again until fill limit
}
return ret
return ret.slice(0, limit)
}
details(url) {
return this.knownLists.find(l => l.url === url)
Expand Down
2 changes: 1 addition & 1 deletion www/nodejs-project/modules/explorer/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1475,7 +1475,7 @@ class ExplorerPrompt extends ExplorerOpenFile {
this.endModal()
this.emit('prompt-end', id)
}
}, config['communitary-mode-lists-amount'])
}, 'submit')
this.inputHelper.stop()

this.emit('prompt-start')
Expand Down
152 changes: 76 additions & 76 deletions www/nodejs-project/modules/lists/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const async = require('async'), Common = require('../lists/common.js')
const pLimit = require('p-limit'), Common = require('../lists/common.js')

class Index extends Common {
constructor(opts){
Expand Down Expand Up @@ -186,88 +186,88 @@ class Index extends Common {
this.searchMapCache[key] = {}
return {}
}
search(terms, opts={}){
return new Promise((resolve, reject) => {
if(typeof(terms) == 'string'){
terms = this.terms(terms, true, true)
}
let start = global.time(), bestResults = [], maybe = [], limit = opts.limit || 256
if(!terms){
return []
async search(terms, opts={}){
if(typeof(terms) == 'string'){
terms = this.terms(terms, true, true)
}
let start = global.time(), bestResults = [], maybe = [], limit = opts.limit || 256
if(!terms){
return []
}
const query = this.parseQuery(terms, opts)
let smap = this.searchMap(query, opts), ks = Object.keys(smap)
if(ks.length){
if(this.debug){
console.warn('M3U SEARCH PRE', terms, opts, (global.time() - start) +'s (pre time)', Object.assign({}, smap), (global.time() - start) +'s', terms)
}
const query = this.parseQuery(terms, opts)
let smap = this.searchMap(query, opts), ks = Object.keys(smap)
if(ks.length){
if(this.debug){
console.warn('M3U SEARCH RESULTS', terms, opts, (global.time() - start) +'s (pre time)', Object.assign({}, smap), (global.time() - start) +'s', terms)
let results = []
ks.forEach(listUrl => {
let ls = smap[listUrl]['n']
if(opts.group){
ls.push(...smap[listUrl]['g'])
}
let results = []
ks.forEach(listUrl => {
let ls = smap[listUrl]['n']
if(opts.group){
ls.push(...smap[listUrl]['g'])
smap[listUrl] = ls
})
const limiter = pLimit(4)
const tasks = ks.map(listUrl => {
return async () => {
if(this.debug){
console.warn('M3U SEARCH ITERATE LIST '+ listUrl, smap[listUrl].slice(0))
}
smap[listUrl] = ls
})
async.eachOfLimit(ks, 4, (listUrl, i, icb) => {
if(listUrl && typeof(this.lists[listUrl]) != 'undefined' && smap[listUrl].length){
if(typeof(this.lists[listUrl]) == 'undefined' || !smap[listUrl].length) return
let i = 0
await this.lists[listUrl].iterate(e => {
i++
if(this.debug){
console.warn('M3U SEARCH ITERATE', smap[listUrl].slice(0))
console.warn('M3U SEARCH ITERATE '+ listUrl +':'+ i +' '+ e.url)
}
this.lists[listUrl].iterate(e => {
if(this.debug){
console.warn('M3U SEARCH ITERATE', e)
}
if(opts.type){
if(this.validateType(e, opts.type, opts.typeStrict === true)){
if(opts.typeStrict === true) {
e.source = listUrl
bestResults.push(e)
} else {
e.source = listUrl
results.push(e)
}
if(opts.type){
if(this.validateType(e, opts.type, opts.typeStrict === true)){
if(opts.typeStrict === true) {
e.source = listUrl
bestResults.push(e)
} else {
e.source = listUrl
results.push(e)
}
} else {
bestResults.push(e)
}
}, smap[listUrl]).catch(console.error).finally(icb)
} else {
icb()
}
}, () => {
if(this.debug){
console.warn('M3U SEARCH RESULTS', (global.time() - start) +'s (partial time)', (global.time() - start) +'s', terms, bestResults.slice(0), results.slice(0), maybe.slice(0))
}
results = bestResults.concat(results)
if(maybe.length){
if(!results.length){
results = maybe
maybe = []
}
}
results = this.tools.dedup(results) // dedup before parentalControl to improve blocking
results = this.prepareEntries(results)
if(opts.parentalControl !== false){
results = this.parentalControl.filter(results, true)
maybe = this.parentalControl.filter(maybe, true)
}
results = this.adjustSearchResults(results, opts, limit)
if(results.length < limit){
maybe = this.adjustSearchResults(maybe, opts, limit - results.length)
} else {
maybe = []
}
if(this.debug){
console.warn('M3U SEARCH RESULTS', (global.time() - start) +'s (total time)', terms)
}
resolve({results, maybe})
smap = bestResults = results = maybe = null
})
} else {
resolve({results:[], maybe: []})
}
})
} else {
bestResults.push(e)
}
}, smap[listUrl])
}
}).map(limiter)
await Promise.allSettled(tasks)
if(this.debug){
console.warn('M3U SEARCH RESULTS', (global.time() - start) +'s (partial time)', (global.time() - start) +'s', terms, bestResults.slice(0), results.slice(0), maybe.slice(0))
}
results = bestResults.concat(results)
if(maybe.length){
if(!results.length){
results = maybe
maybe = []
}
}
results = this.tools.dedup(results) // dedup before parentalControl to improve blocking
results = this.prepareEntries(results)

if(opts.parentalControl !== false){
results = this.parentalControl.filter(results, true)
maybe = this.parentalControl.filter(maybe, true)
}
results = this.adjustSearchResults(results, opts, limit)
if(results.length < limit){
maybe = this.adjustSearchResults(maybe, opts, limit - results.length)
} else {
maybe = []
}
if(this.debug){
console.warn('M3U SEARCH RESULTS*', (global.time() - start) +'s (total time)', terms)
}
return {results, maybe}
} else {
return {results:[], maybe: []}
}
}
getDomain(u){
if(u && u.indexOf('//')!=-1){
Expand Down
56 changes: 47 additions & 9 deletions www/nodejs-project/modules/lists/list-index-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,49 @@ class ListIndexUtils extends Events {
return 'live'
}
}
getRangesFromMap(map) {
const ranges = []
map.forEach(n => ranges.push({start: this.linesMap[n], end: this.linesMap[n + 1] - 1}))
return ranges
}
async readLinesByMap(map) {
const ranges = this.getRangesFromMap(map)
const lines = {}
let fd = null
try {
fd = await fs.promises.open(this.file, 'r')
for (const [index, range] of ranges.entries()) {
const length = range.end - range.start
const buffer = Buffer.alloc(length)
const { bytesRead } = await fd.read(buffer, 0, length, range.start)
if(bytesRead < buffer.length) {
buffer = buffer.slice(0, bytesRead)
}
lines[map[index]] = buffer.toString()
}
} catch (error) {
console.error(error)
} finally {
if (fd !== null) {
try {
await fd.close().catch(console.error)
} catch (error) {
console.error("Error closing file descriptor:", error)
}
}
}
return lines
}
readLines(map){
return new Promise((resolve, reject) => {
if(map){
if(!map.length){
return reject('empty map requested')
}
map.sort()
if(Array.isArray(this.linesMap)) {
return this.readLinesByMap(map).then(resolve).catch(reject)
}
}
fs.stat(this.file, (err, stat) => {
if(err || !stat){
Expand Down Expand Up @@ -78,32 +114,32 @@ class ListIndexUtils extends Events {
})
})
}
async readLastLine(filePath) {
const bufferSize = 1024
const { size } = await fs.promises.stat(filePath)
const fd = await fs.promises.open(filePath, 'r')
async readLastLine() {
const bufferSize = 2048
const { size } = await fs.promises.stat(this.file)
const fd = await fs.promises.open(this.file, 'r')
let line = ''
let readPosition = Math.max(size - bufferSize, 0)
while(readPosition >= 0){
const readSize = Math.min(bufferSize, size - readPosition)
const nextChunk = await fd.read(Buffer.alloc(readSize), 0, readSize, readPosition)
const content = String(nextChunk.buffer)
const { buffer, bytesRead } = await fd.read(Buffer.alloc(readSize), 0, readSize, readPosition)
const content = String(buffer)
line = content + line
const pos = content.lastIndexOf("\n")
if (pos != -1) {
line = line.substring(pos + 1)
break
}
if(!nextChunk.bytesRead) {
if(!bytesRead) {
break
}
readPosition -= nextChunk.bytesRead
readPosition -= bytesRead
}
await fd.close().catch(console.error)
return line
}
async readIndex(){
let line = await this.readLastLine(this.file)
let line = await this.readLastLine()
let index = false
if(line){
try {
Expand All @@ -113,6 +149,8 @@ class ListIndexUtils extends Events {
}
}
if(index && typeof(index.length) != 'undefined'){
this.linesMap = index.linesMap
delete index.linesMap
return index
} else {
console.error('Bad index', String(line).substr(0, 256), this.file)
Expand Down
3 changes: 3 additions & 0 deletions www/nodejs-project/modules/lists/list-index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ListIndex extends ListIndexUtils {
}
entries.forEach((s, i) => {
entries[i]._ = parseInt(ids[i])
if(!entries[i].source) {
entries[i].source = this.url
}
})
}
return entries
Expand Down
7 changes: 2 additions & 5 deletions www/nodejs-project/modules/lists/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,8 @@ class List extends Events {
}
const entries = await this.indexer.entries(map)
for(const e of entries) {
let ret = fn(e)
if(ret instanceof Promise){
await ret
}
return ret === this.constants.BREAK
let ret = await fn(e)
if(ret === this.constants.BREAK) break
}
}
async fetchAll(){
Expand Down
Loading

0 comments on commit 9d243dc

Please sign in to comment.