From cdf4faae9871f99ac5b3b62bcaa9ac1a4f6aba69 Mon Sep 17 00:00:00 2001 From: Shaunak Kishore Date: Sat, 28 Nov 2015 13:24:59 -0500 Subject: [PATCH] Add migration to store frequencies in database --- client/metadata.js | 4 +--- lib/glyphs.js | 5 ++++- server/migration.js | 7 +++++++ 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/client/metadata.js b/client/metadata.js index eb2fa33f..0b248330 100644 --- a/client/metadata.js +++ b/client/metadata.js @@ -80,9 +80,7 @@ Template.metadata.helpers({ }, rank() { const glyph = Session.get('editor.glyph'); - if (!glyph) return '?'; - const data = cjklib.getCharacterData(glyph.character); - return data.frequency || '?'; + return (glyph && glyph.metadata.frequency) || '?'; }, references() { const glyph = Session.get('editor.glyph'); diff --git a/lib/glyphs.js b/lib/glyphs.js index 5018dde3..6b05cb13 100644 --- a/lib/glyphs.js +++ b/lib/glyphs.js @@ -7,7 +7,10 @@ const defaultGlyph = (character) => { return { character: character, codepoint: character.codePointAt(0), - metadata: {kangxi_index: data.kangxi_index}, + metadata: { + frequency: data.frequency, + kangxi_index: data.kangxi_index, + }, stages: {}, } } diff --git a/server/migration.js b/server/migration.js index 002c4fed..7094daf3 100644 --- a/server/migration.js +++ b/server/migration.js @@ -1,5 +1,11 @@ "use strict"; +const addFrequencyField = (glyph) => { + const data = cjklib.getCharacterData(glyph.character); + glyph.metadata.frequency = data.frequency; + Glyphs.save(glyph); +} + const checkStrokeExtractorStability = (glyph) => { const strokes = stroke_extractor.getStrokes( glyph.stages.path, glyph.stages.bridges); @@ -36,6 +42,7 @@ const migrateOldGlyphSchemaToNew = (glyph) => { codepoint: codepoint, metadata: { definition: undefined, + frequency: data.frequency, kangxi_index: data.kangxi_index, pinyin: undefined, strokes: undefined,