Unprocessed should be processed before stale
Signed-off-by: Andre Wanlin <andrewanlin@gmail.com>
This commit is contained in:
@@ -60,9 +60,9 @@ export class LinguistBackendDatabase implements LinguistBackendStore {
|
||||
// (undocumented)
|
||||
getEntityResults(entityRef: string): Promise<Languages>;
|
||||
// (undocumented)
|
||||
getProcessedEntities(): Promise<ProcessedEntity[] | []>;
|
||||
getProcessedEntities(): Promise<ProcessedEntity[]>;
|
||||
// (undocumented)
|
||||
getUnprocessedEntities(): Promise<string[] | []>;
|
||||
getUnprocessedEntities(): Promise<string[]>;
|
||||
// (undocumented)
|
||||
insertEntityResults(entityLanguages: EntityResults): Promise<string>;
|
||||
// (undocumented)
|
||||
@@ -74,9 +74,9 @@ export interface LinguistBackendStore {
|
||||
// (undocumented)
|
||||
getEntityResults(entityRef: string): Promise<Languages>;
|
||||
// (undocumented)
|
||||
getProcessedEntities(): Promise<ProcessedEntity[] | []>;
|
||||
getProcessedEntities(): Promise<ProcessedEntity[]>;
|
||||
// (undocumented)
|
||||
getUnprocessedEntities(): Promise<string[] | []>;
|
||||
getUnprocessedEntities(): Promise<string[]>;
|
||||
// (undocumented)
|
||||
insertEntityResults(entityLanguages: EntityResults): Promise<string>;
|
||||
// (undocumented)
|
||||
|
||||
@@ -234,10 +234,10 @@ describe('Linguist backend API', () => {
|
||||
expect(overview.staleCount).toEqual(1);
|
||||
expect(overview.pendingCount).toEqual(4);
|
||||
expect(overview.filteredEntities).toEqual([
|
||||
'component:default/stale-service-two',
|
||||
'component:default/service-three',
|
||||
'component:default/service-four',
|
||||
'component:default/service-five',
|
||||
'component:default/stale-service-two',
|
||||
]);
|
||||
});
|
||||
|
||||
|
||||
@@ -175,7 +175,7 @@ export class LinguistBackendClient implements LinguistBackendApi {
|
||||
.map(pe => pe.entityRef);
|
||||
|
||||
const unprocessedEntities = await this.store.getUnprocessedEntities();
|
||||
const filteredEntities = staleEntities.concat(unprocessedEntities);
|
||||
const filteredEntities = unprocessedEntities.concat(staleEntities);
|
||||
|
||||
const entitiesOverview: EntitiesOverview = {
|
||||
entityCount: unprocessedEntities.length + processedEntities.length,
|
||||
|
||||
@@ -134,6 +134,13 @@ describe('Linguist database', () => {
|
||||
expect(unprocessedEntities).toMatchObject(validUnprocessedEntities);
|
||||
});
|
||||
|
||||
it('should return string[] when there is no unprocessed entities', async () => {
|
||||
await testDbClient('entity_result').delete();
|
||||
const unprocessedEntities = await store.getUnprocessedEntities();
|
||||
|
||||
expect(unprocessedEntities).toMatchObject([]);
|
||||
});
|
||||
|
||||
it('should be able to return processed entities', async () => {
|
||||
const validProcessedEntities: ProcessedEntity[] = [
|
||||
{
|
||||
@@ -155,6 +162,13 @@ describe('Linguist database', () => {
|
||||
expect(processedEntities).toMatchObject(validProcessedEntities);
|
||||
});
|
||||
|
||||
it('should return string[] when there is no processed entities', async () => {
|
||||
await testDbClient('entity_result').delete();
|
||||
const unprocessedEntities = await store.getProcessedEntities();
|
||||
|
||||
expect(unprocessedEntities).toMatchObject([]);
|
||||
});
|
||||
|
||||
it('should insert new entities and ignore duplicates', async () => {
|
||||
const before = testDbClient.count('entity_result');
|
||||
|
||||
|
||||
@@ -35,8 +35,8 @@ export interface LinguistBackendStore {
|
||||
insertEntityResults(entityLanguages: EntityResults): Promise<string>;
|
||||
insertNewEntity(entityRef: string): Promise<void>;
|
||||
getEntityResults(entityRef: string): Promise<Languages>;
|
||||
getProcessedEntities(): Promise<ProcessedEntity[] | []>;
|
||||
getUnprocessedEntities(): Promise<string[] | []>;
|
||||
getProcessedEntities(): Promise<ProcessedEntity[]>;
|
||||
getUnprocessedEntities(): Promise<string[]>;
|
||||
}
|
||||
|
||||
const migrationsDir = resolvePackagePath(
|
||||
@@ -108,7 +108,7 @@ export class LinguistBackendDatabase implements LinguistBackendStore {
|
||||
}
|
||||
}
|
||||
|
||||
async getProcessedEntities(): Promise<ProcessedEntity[] | []> {
|
||||
async getProcessedEntities(): Promise<ProcessedEntity[]> {
|
||||
const rawEntities = await this.db<RawDbEntityResultRow>('entity_result')
|
||||
.whereNotNull('processed_date')
|
||||
.whereNotNull('languages');
|
||||
@@ -140,7 +140,7 @@ export class LinguistBackendDatabase implements LinguistBackendStore {
|
||||
return processedEntities;
|
||||
}
|
||||
|
||||
async getUnprocessedEntities(): Promise<string[] | []> {
|
||||
async getUnprocessedEntities(): Promise<string[]> {
|
||||
const rawEntities = await this.db<RawDbEntityResultRow>('entity_result')
|
||||
// TODO(ahhhndre) processed_date should always be null as well but it had a default to the current date
|
||||
// once the default has been removed and released, we can then come back an enable this check
|
||||
|
||||
Reference in New Issue
Block a user