Revert "ui: Use `X-Range` header/meta to decide whether to reconcile or not"

This reverts commit e9f6361d26.
This commit is contained in:
John Cowen 2020-07-27 09:41:16 +00:00
parent 4b02673d82
commit e83c31b070
7 changed files with 40 additions and 29 deletions

View File

@ -92,11 +92,7 @@ export default Serializer.extend({
// and they need the slug key AND potential namespace in order to
// create the correct uid/fingerprint
return {
[primaryKey]: this.fingerprint(
primaryKey,
slugKey,
data[DATACENTER_KEY]
)({
[primaryKey]: this.fingerprint(primaryKey, slugKey, data[DATACENTER_KEY])({
[slugKey]: data[slugKey],
[NSPACE_KEY]: data[NSPACE_KEY],
})[primaryKey],
@ -155,9 +151,6 @@ export default Serializer.extend({
dc: headers[HTTP_HEADERS_DATACENTER.toLowerCase()],
nspace: headers[HTTP_HEADERS_NAMESPACE.toLowerCase()],
};
if (typeof headers['x-range'] !== 'undefined') {
meta.range = headers['x-range'];
}
if (requestType === 'query') {
meta.date = this.timestamp();
payload.forEach(function(item) {

View File

@ -68,7 +68,7 @@ const parseBody = function(strs, ...values) {
return [body, ...values];
};
const CLIENT_HEADERS = [CACHE_CONTROL, 'X-Request-ID', 'X-Range'];
const CLIENT_HEADERS = [CACHE_CONTROL, 'X-Request-ID'];
export default Service.extend({
dom: service('dom'),
connections: service('client/connections'),

View File

@ -33,17 +33,16 @@ export default Service.extend({
// so we might get urls like //dc/services
let find;
const repo = this[model];
configuration.createEvent = function(result = {}, configuration) {
const event = {
type: 'message',
data: result,
if (repo.shouldReconcile(src)) {
configuration.createEvent = function(result = {}, configuration) {
const event = {
type: 'message',
data: result,
};
repo.reconcile(get(event, 'data.meta'));
return event;
};
const meta = get(event, 'data.meta') || {};
if (typeof meta.range === 'undefined') {
repo.reconcile(meta);
}
return event;
};
}
let method, slug;
switch (model) {
case 'datacenters':

View File

@ -15,6 +15,9 @@ export default Service.extend({
},
//
store: service('store'),
shouldReconcile: function(method) {
return true;
},
reconcile: function(meta = {}) {
// unload anything older than our current sync date/time
if (typeof meta.date !== 'undefined') {

View File

@ -12,6 +12,15 @@ export default RepositoryService.extend({
delete obj.Namespace;
return this._super(obj);
},
shouldReconcile: function(method) {
// TODO: This is to be switched out for something at an adapter level
// so it works for both methods of interacting with data-sources
switch (true) {
case method === 'findByService' || method.indexOf('for-service') !== -1:
return false;
}
return this._super(...arguments);
},
findByService: function(slug, dc, nspace, configuration = {}) {
const query = {
dc: dc,

View File

@ -5,6 +5,13 @@ export default RepositoryService.extend({
getModelName: function() {
return modelName;
},
shouldReconcile: function(method) {
switch (method) {
case 'findGatewayBySlug':
return false;
}
return this._super(...arguments);
},
findBySlug: function(slug, dc) {
return this._super(...arguments).then(function(item) {
// TODO: Move this to the Serializer

View File

@ -9,17 +9,17 @@ import { cache as createCache, BlockingEventSource } from 'consul-ui/utils/dom/e
const createProxy = function(repo, find, settings, cache, serialize = JSON.stringify) {
const client = this.client;
// custom createEvent, here used to reconcile the ember-data store for each tick
const createEvent = function(result = {}, configuration) {
const event = {
type: 'message',
data: result,
let createEvent;
if (repo.shouldReconcile(find)) {
createEvent = function(result = {}, configuration) {
const event = {
type: 'message',
data: result,
};
repo.reconcile(get(event, 'data.meta'));
return event;
};
const meta = get(event, 'data.meta') || {};
if (typeof meta.range === 'undefined') {
repo.reconcile(meta);
}
return event;
};
}
// proxied find*..(id, dc)
return function() {
const key = `${repo.getModelName()}.${find}.${serialize([...arguments])}`;