Don't send 404s for unknown opcodes (makes things messier in js console and caching). Use client-side caching to prevent unnecessary fetches.

dev/git-series/gccdum
Matt Godbolt 6 years ago
parent 07926d72e2
commit 4d6e95c6f3

@ -43,15 +43,15 @@ function docHandler(req, res, next) {
if (staticMaxAgeSecs) {
res.setHeader('Cache-Control', 'public, max-age=' + staticMaxAgeSecs);
}
if (!info) {
return res.status(404).send("Unknown opcode");
}
if (req.accepts(['text', 'json']) == 'json') {
res.set('Content-Type', 'application/json');
res.end(JSON.stringify(info));
} else {
res.set('Content-Type', 'text/html');
res.end(info.html);
if (info)
res.end(info.html);
else
res.end("Unknown opcode");
}
}

@ -555,7 +555,16 @@ define(function (require) {
return null;
}
var opcodeLike = /^[a-zA-Z][a-zA-Z0-9_.]+$/; // at least two characters
var getAsmInfo = function (opcode) {
if (!opcodeLike.exec(opcode)) {
return Promise.reject("Not an opcode");
}
var cacheName = "asm/" + opcode;
var cached = Cache.get(cacheName);
if (cached) {
return cached;
}
var promise = new Promise(function (resolve, reject) {
$.ajax({
type: 'GET',
@ -563,6 +572,7 @@ define(function (require) {
dataType: 'json', // Expected,
contentType: 'text/plain', // Sent
success: function (result) {
Cache.set(cacheName, result);
resolve(result);
},
error: function (result) {
@ -595,7 +605,7 @@ define(function (require) {
}
if (this.settings.hoverShowAsmDoc === true) {
getAsmInfo(currentWord.word).then(_.bind(function(response) {
getAsmInfo(currentWord.word).then(_.bind(function (response) {
this.decorations.asmToolTip = {
range: e.target.range,
options: {

Loading…
Cancel
Save