OPCIÓN A: A2 Virtual Scroll + A3 Celery + A4 asyncpg PoC + A5 particionamiento
A2 — Virtual scroll en tablas grandes: - Nuevo helper VirtualScroll en pos/static/js/virtual-scroll.js - inventory.js: tabla de productos con virtual scroll - customers.js: tabla de clientes con virtual scroll - fleet.js: renderMaintenance() y renderHistory() con virtual scroll - Templates envueltos en .vs-container para scroll A3 — Celery worker queue: - pos/celery_app.py + pos/tasks.py (warm cache, bulk import, reports) - Blueprint tasks_bp.py con endpoints /pos/api/tasks/* - Script scripts/start_celery.sh A4 — asyncpg + Quart PoC: - pos/async_catalog.py: endpoint /pos/api/catalog/async-search - scripts/benchmark_async_catalog.py: benchmark Flask vs Quart A5 — Particionar vehicle_parts: - scripts/partition_vehicle_parts.py: migración segura por hash (16 particiones) - Soporta --dry-run, --skip-swap, --skip-drop Tests: 36/36 pasando
This commit is contained in:
155
pos/static/js/virtual-scroll.js
Normal file
155
pos/static/js/virtual-scroll.js
Normal file
@@ -0,0 +1,155 @@
|
||||
/**
|
||||
* virtual-scroll.js — Lightweight vanilla-JS virtual scroll helper.
|
||||
* Supports <div> containers and <tbody> tables.
|
||||
*
|
||||
* Usage:
|
||||
* var vs = new VirtualScroll({
|
||||
* container: document.getElementById('myTableBody'),
|
||||
* rowHeight: 48,
|
||||
* buffer: 5,
|
||||
* renderRow: function(item, index) { return '<tr>...</tr>'; }
|
||||
* });
|
||||
* vs.setData(arrayOfItems);
|
||||
*/
|
||||
(function(window) {
|
||||
'use strict';
|
||||
|
||||
function VirtualScroll(opts) {
|
||||
this.container = opts.container;
|
||||
this.rowHeight = opts.rowHeight || 48;
|
||||
this.buffer = opts.buffer || 5;
|
||||
this.renderRow = opts.renderRow || function() { return ''; };
|
||||
this.emptyHtml = opts.emptyHtml || '';
|
||||
this.data = [];
|
||||
this._scrollHandler = this._onScroll.bind(this);
|
||||
this._resizeHandler = this._onResize.bind(this);
|
||||
this._isTbody = this.container.tagName === 'TBODY';
|
||||
this._init();
|
||||
}
|
||||
|
||||
VirtualScroll.prototype._init = function() {
|
||||
var c = this.container;
|
||||
if (!this._isTbody) {
|
||||
c.style.overflowY = 'auto';
|
||||
c.style.position = 'relative';
|
||||
if (!c.style.maxHeight && !c.style.height) {
|
||||
c.style.maxHeight = '60vh';
|
||||
}
|
||||
} else {
|
||||
// For tbody, scroll is on the parent element (table wrapper)
|
||||
var table = c.closest('table');
|
||||
if (table) {
|
||||
var wrapper = table.parentElement;
|
||||
if (wrapper && wrapper.classList.contains('vs-container')) {
|
||||
wrapper.addEventListener('scroll', this._scrollHandler, { passive: true });
|
||||
}
|
||||
}
|
||||
}
|
||||
window.addEventListener('resize', this._resizeHandler, { passive: true });
|
||||
};
|
||||
|
||||
VirtualScroll.prototype.setData = function(data) {
|
||||
this.data = data || [];
|
||||
this._render();
|
||||
};
|
||||
|
||||
VirtualScroll.prototype.refresh = function() {
|
||||
this._render();
|
||||
};
|
||||
|
||||
VirtualScroll.prototype._onScroll = function() {
|
||||
this._render();
|
||||
};
|
||||
|
||||
VirtualScroll.prototype._onResize = function() {
|
||||
this._render();
|
||||
};
|
||||
|
||||
VirtualScroll.prototype._getScrollTop = function() {
|
||||
if (this._isTbody) {
|
||||
var table = this.container.closest('table');
|
||||
if (table) {
|
||||
var wrapper = table.parentElement;
|
||||
if (wrapper && wrapper.classList.contains('vs-container')) {
|
||||
return wrapper.scrollTop;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
return this.container.scrollTop;
|
||||
};
|
||||
|
||||
VirtualScroll.prototype._getContainerHeight = function() {
|
||||
if (this._isTbody) {
|
||||
var table = this.container.closest('table');
|
||||
if (table) {
|
||||
var wrapper = table.parentElement;
|
||||
if (wrapper && wrapper.classList.contains('vs-container')) {
|
||||
return wrapper.clientHeight;
|
||||
}
|
||||
}
|
||||
return 600;
|
||||
}
|
||||
return this.container.clientHeight;
|
||||
};
|
||||
|
||||
VirtualScroll.prototype._render = function() {
|
||||
var data = this.data;
|
||||
var rowH = this.rowHeight;
|
||||
var buffer = this.buffer;
|
||||
|
||||
if (!data.length) {
|
||||
if (this._isTbody) {
|
||||
this.container.innerHTML = this.emptyHtml;
|
||||
} else {
|
||||
this.container.innerHTML = this.emptyHtml;
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
var scrollTop = this._getScrollTop();
|
||||
var containerHeight = this._getContainerHeight();
|
||||
var startIdx = Math.max(0, Math.floor(scrollTop / rowH) - buffer);
|
||||
var endIdx = Math.min(data.length, Math.ceil((scrollTop + containerHeight) / rowH) + buffer);
|
||||
|
||||
var html = '';
|
||||
if (this._isTbody) {
|
||||
// Top spacer row
|
||||
var topSpacerHeight = startIdx * rowH;
|
||||
if (topSpacerHeight > 0) {
|
||||
html += '<tr style="height:' + topSpacerHeight + 'px;"><td colspan="99" style="padding:0;border:0;"></td></tr>';
|
||||
}
|
||||
for (var i = startIdx; i < endIdx; i++) {
|
||||
html += this.renderRow(data[i], i);
|
||||
}
|
||||
// Bottom spacer row
|
||||
var bottomSpacerHeight = (data.length - endIdx) * rowH;
|
||||
if (bottomSpacerHeight > 0) {
|
||||
html += '<tr style="height:' + bottomSpacerHeight + 'px;"><td colspan="99" style="padding:0;border:0;"></td></tr>';
|
||||
}
|
||||
} else {
|
||||
for (var j = startIdx; j < endIdx; j++) {
|
||||
html += this.renderRow(data[j], j);
|
||||
}
|
||||
}
|
||||
|
||||
this.container.innerHTML = html;
|
||||
};
|
||||
|
||||
VirtualScroll.prototype.destroy = function() {
|
||||
if (this._isTbody) {
|
||||
var table = this.container.closest('table');
|
||||
if (table) {
|
||||
var wrapper = table.parentElement;
|
||||
if (wrapper && wrapper.classList.contains('vs-container')) {
|
||||
wrapper.removeEventListener('scroll', this._scrollHandler);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
this.container.removeEventListener('scroll', this._scrollHandler);
|
||||
}
|
||||
window.removeEventListener('resize', this._resizeHandler);
|
||||
};
|
||||
|
||||
window.VirtualScroll = VirtualScroll;
|
||||
})(window);
|
||||
Reference in New Issue
Block a user